2019-05-13 20:58:37 +00:00
|
|
|
# ascii-table
|
|
|
|
|
|
|
|
Print ASCII tables to the terminal.
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
```
|
2020-04-01 19:18:07 +00:00
|
|
|
use ascii_table::AsciiTable;
|
2019-05-13 20:58:37 +00:00
|
|
|
|
2020-04-01 19:18:07 +00:00
|
|
|
let ascii_table = AsciiTable::default();
|
2019-05-13 20:58:37 +00:00
|
|
|
let data = vec![&[1, 2, 3], &[4, 5, 6], &[7, 8, 9]];
|
2020-04-01 19:18:07 +00:00
|
|
|
ascii_table.print(data);
|
2019-05-13 20:58:37 +00:00
|
|
|
// ┌───┬───┬───┐
|
|
|
|
// │ 1 │ 2 │ 3 │
|
|
|
|
// │ 4 │ 5 │ 6 │
|
|
|
|
// │ 7 │ 8 │ 9 │
|
|
|
|
// └───┴───┴───┘
|
|
|
|
```
|
2020-04-01 20:12:24 +00:00
|
|
|
|
|
|
|
## 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+ │
|
|
|
|
// └─────┴─────┴─────┴──────┘
|
|
|
|
```
|