//! This example shows how to use a custom formatter configuration. use kitty_table::{Column, ColumnAlign, ColumnSize, TableFormatter}; pub fn main() { // Import these two fields for brevity in the following section. use ColumnAlign::*; use ColumnSize::*; let formatter = TableFormatter::new([ // Column 1 will use the default settings. These are used by tuples. Column::default(), // This is the same as column 1, but written more explicitly. // It has no title, will fit the data in its column, is left-aligned, // and has a padding of 1 space Column::new(None, Contain, Left, 1), // Similar to column 2, but has a title. // This column will grow to accomodate its data, but only up to 7 // characters— data will be split with newlines if needed. // // Because this column has a title, all columns without titles in // this graph will get a blank title when printed. Column::new(Some(("Fruit", Left)), ContainMax(5), Left, 1), // This column has a fixed width of 32, and has 5 spaces // of padding around the data, which is centered. Note that the // actual width of this column will be 42 (32 + 5 + 5) due // to the padding. Column::new(None, Fixed(12), Centered, 5), // You should be able to tell how this one will look by this point. Column::new(Some(("Data", Centered)), Fixed(8), Right, 1), ]); // The above formatter has 5 columns specified, so any data we put in // must turn into a [String; 5] with DebugTableRow— this is true // for length-5 tuples. let data = [ (1, 'H', "Apple", true, 2.3), (2, 'E', "Pineapple", false, 5.5), (3, 'L', "Kiwi", false, 11.5), (4, 'L', "Banana", true, 0.5), (5, 'O', "Strawberry", false, 0.25) ]; // Print data just as normal. let _ = formatter.debug_print(data); } /* Expected result: ┏━━━┳━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┓ ┃ ┃ ┃ Fruit ┃ ┃ Data ┃ ┣━━━╇━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━┫ ┃ 1 │ 'H' │ "Appl │ true │ 2.3 ┃ ┃ │ │ e" │ │ ┃ ┠───┼─────┼───────┼──────────────────────┼──────────┨ ┃ 2 │ 'E' │ "Pine │ false │ 5.5 ┃ ┃ │ │ apple │ │ ┃ ┃ │ │ " │ │ ┃ ┠───┼─────┼───────┼──────────────────────┼──────────┨ ┃ 3 │ 'L' │ "Kiwi │ false │ 11.5 ┃ ┃ │ │ " │ │ ┃ ┠───┼─────┼───────┼──────────────────────┼──────────┨ ┃ 4 │ 'L' │ "Bana │ true │ 0.5 ┃ ┃ │ │ na" │ │ ┃ ┠───┼─────┼───────┼──────────────────────┼──────────┨ ┃ 5 │ 'O' │ "Stra │ false │ 0.25 ┃ ┃ │ │ wberr │ │ ┃ ┃ │ │ y" │ │ ┃ ┗━━━┷━━━━━┷━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━┛ */