diff --git a/lib/entry/libimagentrylist/src/listers/table.rs b/lib/entry/libimagentrylist/src/listers/table.rs index 46585c63..6301e18e 100644 --- a/lib/entry/libimagentrylist/src/listers/table.rs +++ b/lib/entry/libimagentrylist/src/listers/table.rs @@ -34,6 +34,7 @@ pub struct TableLister Vec> { header: Option>, with_idx: bool, + print_empty: bool, } impl Vec> TableLister { @@ -43,6 +44,7 @@ impl Vec> TableLister { line_generator: gen, header: None, with_idx: true, + print_empty: false, } } @@ -56,6 +58,11 @@ impl Vec> TableLister { self } + pub fn print_empty(mut self, b: bool) -> TableLister { + self.print_empty = b; + self + } + } impl Vec> Lister for TableLister { @@ -81,6 +88,8 @@ impl Vec> Lister for TableLister { }, } + let mut entries_added = 0; + entries.enumerate().fold(Ok(table), |table, (i, entry)| { table.and_then(|mut table| { let mut v = (self.line_generator)(&entry); @@ -102,12 +111,17 @@ impl Vec> Lister for TableLister { } table.add_row(v.iter().map(|s| Cell::new(s)).collect()); + entries_added += 1; Ok(table) }) }) .and_then(|tbl| { - let mut io = stdout(); - tbl.print(&mut io).chain_err(|| LEK::IOError) + if entries_added != 0 && !self.print_empty { + let mut io = stdout(); + tbl.print(&mut io).chain_err(|| LEK::IOError) + } else { + Ok(()) + } }) }