style/
style.rs

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