13 stable releases (4 major)

Uses new Rust 2024

4.0.6 Feb 25, 2025
4.0.5 Nov 20, 2024
4.0.4 Aug 28, 2024
4.0.3 Aug 28, 2023
0.1.1 May 13, 2019

#55 in Command-line interface

Download history 2058/week @ 2024-11-20 1707/week @ 2024-11-27 1674/week @ 2024-12-04 1715/week @ 2024-12-11 1410/week @ 2024-12-18 1293/week @ 2024-12-25 1893/week @ 2025-01-01 2025/week @ 2025-01-08 1856/week @ 2025-01-15 2800/week @ 2025-01-22 2690/week @ 2025-01-29 2661/week @ 2025-02-05 2505/week @ 2025-02-12 2711/week @ 2025-02-19 2334/week @ 2025-02-26 2291/week @ 2025-03-05

10,362 downloads per month
Used in 15 crates (13 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
~14K SLoC