1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
use prettytable::{ format::{self, TableFormat}, row::Row, Table, }; lazy_static! { pub static ref FORMAT_BASIC: TableFormat = format::FormatBuilder::new() .column_separator('│') .borders('│') .separators( &[format::LinePosition::Top], format::LineSeparator::new('─', '┬', '┌', '┐') ).separators( &[format::LinePosition::Intern], format::LineSeparator::new('─', '┼', '├', '┤') ).separators( &[format::LinePosition::Bottom], format::LineSeparator::new('─', '┴', '└', '┘') ).padding(1, 1) .build(); } pub fn format_table<'a, RowIter, MsgFn>(title: Row, empty_msg: MsgFn, it: RowIter) where RowIter: Iterator<Item = Row>, MsgFn: FnOnce() -> &'a str, { let mut table = Table::new(); table.set_titles(title); let mut show = false; for row in it { table.add_row(row); show = true; } if show { table.set_format(*FORMAT_BASIC); table.printstd() } else { eprintln!("{}", empty_msg()) } }