Skip to main content

styled/
styled.rs

1use tiny_table::{Align, Cell, Column, ColumnWidth, SectionStyle, Table, Trunc};
2
3fn main() {
4    let mut table = Table::with_columns(vec![
5        Column::new("Name")
6            .bright_cyan()
7            .bold()
8            .width(ColumnWidth::fill()),
9        Column::new("Role").width(0.5).truncate(Trunc::Middle),
10        Column::new("Status").bright_yellow().bold().width(0.3),
11    ])
12    .with_section_style(SectionStyle {
13        horiz: "═",
14        mid_left: "╞",
15        mid_right: "╡",
16        mid_joint: "╪",
17    })
18    .with_separator_style(SectionStyle {
19        horiz: "╌",
20        mid_joint: "│",
21        ..SectionStyle::unicode()
22    });
23
24    table.add_section("Team").align(Align::Center);
25    table.add_row(vec![
26        Cell::new("Ada Lovelace"),
27        Cell::new("Principal Engineer"),
28        Cell::new("Active").bright_green(),
29    ]);
30
31    table.add_separator();
32    table.add_row(vec![
33        Cell::new("Bob"),
34        Cell::new("Support"),
35        Cell::new("Away"),
36    ]);
37
38    println!("{}", table);
39}