style/
style.rs

1use prettytable::{cell, ptable, row, table};
2use prettytable::{color, Attr};
3use prettytable::{Cell, Row, Table};
4
5#[allow(dead_code)]
6fn main() {
7    let _ = table!();
8    let mut table = Table::new();
9    // Add style to a cell
10    table.add_row(row![FrByb->"ABC", "DEFG", "HIJKLMN"]);
11    // Add style to a full row
12    table.add_row(row![FY => "styled", "bar", "foo"]);
13    table.add_row(Row::new(vec![
14        Cell::new("foobar2"),
15        // Create a cell with a red foreground color
16        Cell::new("bar2").with_style(Attr::ForegroundColor(color::RED)),
17        // Create a cell with red foreground color, yellow background color, with bold characters
18        Cell::new("foo2").style_spec("FrByb"),
19        // Using the cell! macro
20        cell!(Fr->"red"),
21    ]));
22
23    table.printstd();
24
25    // Print a table with some styles on it :
26    // FrBybl means : Foregound red, Background yellow, bold, left align
27    ptable!([FrBybl->"A", "B", FrBybr->"C"], [123, 234, 345, 456], [Fg => 1, 2, 3]);
28
29    // You can also apply style to full rows :
30    let mut table = table!([Frb => "A", "B", "C"], [1, 2, 3, 4], ["A\nBCCZZZ\nDDD", 2, table]);
31    // Set a title line, with all text centered in the cell
32    table.set_titles(row![c => "Title 1", "Title 2"]);
33    table.printstd();
34}