simple/simple.rs
1use stybulate::*;
2
3fn main() {
4 // A simple table with strings and numbers and the default alignments
5 let mut table = Table::new(
6 Style::Fancy,
7 vec![
8 vec![Cell::from("spam"), Cell::Float(41.9999)],
9 vec![Cell::from("eggs"), Cell::Int(451)],
10 ],
11 Some(Headers::from(vec!["strings", "numbers"])),
12 );
13 println!("{}", table.tabulate());
14 /* Will print:
15 ╒═══════════╤═══════════╕
16 │ strings │ numbers │
17 ╞═══════════╪═══════════╡
18 │ spam │ 41.9999 │
19 ├───────────┼───────────┤
20 │ eggs │ 451 │
21 ╘═══════════╧═══════════╛
22 */
23
24 // Alignment can be changed like so:
25 table.set_align(Align::Right, Align::Center);
26 println!("{}", table.tabulate());
27 /* Will print:
28 ╒═══════════╤═══════════╕
29 │ strings │ numbers │
30 ╞═══════════╪═══════════╡
31 │ spam │ 41.9999 │
32 ├───────────┼───────────┤
33 │ eggs │ 451.0000 │
34 ╘═══════════╧═══════════╛
35 */
36
37 // With the feature "ansi_term_style", the borders style can be changed like so:
38 table.set_border_style(ansi_term::Color::Cyan.bold());
39 println!("{}", table.tabulate());
40 // Will print same as above but with bold and colored borders
41}