#ascii #table

ascii_table

Print ASCII tables to the terminal

8 releases (stable)

3.0.2 Nov 30, 2020
3.0.1 May 17, 2020
3.0.0 Apr 2, 2020
2.1.0 Dec 26, 2019
0.1.1 May 13, 2019

#34 in Command-line interface

Download history 536/week @ 2021-02-25 654/week @ 2021-03-04 468/week @ 2021-03-11 575/week @ 2021-03-18 646/week @ 2021-03-25 458/week @ 2021-04-01 486/week @ 2021-04-08 948/week @ 2021-04-15 685/week @ 2021-04-22 587/week @ 2021-04-29 1084/week @ 2021-05-06 760/week @ 2021-05-13 398/week @ 2021-05-20 516/week @ 2021-05-27 415/week @ 2021-06-03 1012/week @ 2021-06-10

2,762 downloads per month
Used in 5 crates

MIT license

38KB
906 lines

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, Column, Align};

let mut ascii_table = AsciiTable::default();
ascii_table.max_width = 26;

let mut column = Column::default();
column.header = "H1".into();
column.align = Align::Left;
ascii_table.columns.insert(0, column);

let mut column = Column::default();
column.header = "H2".into();
column.align = Align::Center;
ascii_table.columns.insert(1, column);

let mut column = Column::default();
column.header = "H3".into();
column.align = Align::Right;
ascii_table.columns.insert(2, column);

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+ │
// └─────┴─────┴─────┴──────┘

No runtime deps