table_layouts/
table_layouts.rs1use scriba::{Format, Output, Table, Ui};
13
14fn main() -> scriba::Result<()> {
15 let headers = vec!["Product".into(), "Price".into(), "Stock".into()];
16 let rows = vec![
17 vec!["Widget A".into(), "$9.99".into(), "42".into()],
18 vec!["Widget B".into(), "$14.50".into(), "18".into()],
19 vec!["Widget C".into(), "$24.99".into(), "0".into()],
20 ];
21
22 let ui = Ui::new().with_format(Format::Text);
23
24 println!("=== FULL LAYOUT ===");
26 println!("(Bordered, full width — best for normal terminals)\n");
27
28 let table_full = Table::new(headers.clone(), rows.clone()).with_layout_full();
29 let output_full = Output::new()
30 .heading(2, "Inventory")
31 .table(None, table_full);
32
33 ui.print(&output_full)?;
34
35 println!("\n=== COMPACT LAYOUT ===");
37 println!("(Minimal spacing, no borders — dense display)\n");
38
39 let table_compact = Table::new(headers.clone(), rows.clone()).with_layout_compact();
40 let output_compact = Output::new()
41 .heading(2, "Inventory")
42 .table(None, table_compact);
43
44 ui.print(&output_compact)?;
45
46 println!("\n=== STACKED LAYOUT ===");
48 println!("(Key-value per row — great for narrow terminals)\n");
49
50 let table_stacked = Table::new(headers.clone(), rows.clone()).with_layout_stacked();
51 let output_stacked = Output::new()
52 .heading(2, "Inventory")
53 .table(None, table_stacked);
54
55 ui.print(&output_stacked)?;
56
57 println!("\n=== STACKED LAYOUT WITH INDEX ===");
59 println!("(Row numbers for reference)\n");
60
61 let table_stacked_idx = Table::new(headers.clone(), rows.clone())
62 .with_index()
63 .with_layout_stacked();
64 let output_idx = Output::new()
65 .heading(2, "Inventory")
66 .table(None, table_stacked_idx);
67
68 ui.print(&output_idx)?;
69
70 println!("\n=== COMPACT LAYOUT WITH INDEX ===");
72 println!("(Minimal display with row numbers)\n");
73
74 let table_compact_idx = Table::new(headers.clone(), rows.clone())
75 .with_index()
76 .with_layout_compact();
77 let output_compact_idx = Output::new()
78 .heading(2, "Inventory")
79 .table(None, table_compact_idx);
80
81 ui.print(&output_compact_idx)?;
82
83 Ok(())
84}