#ascii #table

ascii_table

Print ASCII tables to the terminal

9 stable releases (4 major)

4.0.2 Jan 25, 2022
3.0.2 Nov 30, 2020
3.0.1 May 17, 2020
2.1.0 Dec 26, 2019
0.1.1 May 13, 2019

#90 in Command-line interface

Download history 595/week @ 2023-02-04 685/week @ 2023-02-11 856/week @ 2023-02-18 844/week @ 2023-02-25 1173/week @ 2023-03-04 894/week @ 2023-03-11 974/week @ 2023-03-18 853/week @ 2023-03-25 1359/week @ 2023-04-01 1096/week @ 2023-04-08 1257/week @ 2023-04-15 922/week @ 2023-04-22 1356/week @ 2023-04-29 882/week @ 2023-05-06 1018/week @ 2023-05-13 750/week @ 2023-05-20

4,187 downloads per month
Used in 8 crates

MIT license

41KB
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–315KB