12 stable releases (4 major)

4.0.5 Nov 20, 2024
4.0.3 Aug 28, 2023
4.0.2 Jan 25, 2022
3.0.2 Nov 30, 2020
0.1.1 May 13, 2019

#62 in Command-line interface

Download history 1763/week @ 2024-08-22 1752/week @ 2024-08-29 2246/week @ 2024-09-05 2466/week @ 2024-09-12 2470/week @ 2024-09-19 1914/week @ 2024-09-26 1973/week @ 2024-10-03 2413/week @ 2024-10-10 2031/week @ 2024-10-17 1896/week @ 2024-10-24 1705/week @ 2024-10-31 1425/week @ 2024-11-07 2172/week @ 2024-11-14 1712/week @ 2024-11-21 1739/week @ 2024-11-28 1297/week @ 2024-12-05

7,118 downloads per month
Used in 13 crates (12 directly)

MIT license

43KB
1K SLoC

ascii-table

Print ASCII tables to the terminal.

Example

use ascii_table::AsciiTable;

let ascii_table = AsciiTable::default();
let data = vec![&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]];
ascii_table.print(data);
// ┌───┬───┬───┐
// │ 1 │ 2 │ 3 │
// │ 4 │ 5 │ 6 │
// │ 7 │ 8 │ 9 │
// └───┴───┴───┘

Example

use std::fmt::Display;
use ascii_table::{AsciiTable, Align};

let mut ascii_table = AsciiTable::default();
ascii_table.set_max_width(26);
ascii_table.column(0).set_header("H1").set_align(Align::Left);
ascii_table.column(1).set_header("H2").set_align(Align::Center);
ascii_table.column(2).set_header("H3").set_align(Align::Right);

let data: Vec<Vec<&dyn Display>> = vec![
    vec![&'v', &'v', &'v'],
    vec![&123, &456, &789, &"abcdef"]
];
ascii_table.print(data);
// ┌─────┬─────┬─────┬──────┐
// │ H1  │ H2  │ H3  │      │
// ├─────┼─────┼─────┼──────┤
// │ v   │  v  │   v │      │
// │ 123 │ 456 │ 789 │ abc+ │
// └─────┴─────┴─────┴──────┘

Features

  • auto_table_width: Sets the default max width of the ascii table to the width of the terminal.
  • color_codes: Correctly calculates the width of a string when terminal color codes are present (like those from the colorful crate).
  • wide_characters: Correctly calculates the width of a string when wide characters are present (like emoli's).

Dependencies

~0–1MB
~15K SLoC