TableLister: If configured with index, also print index row

This commit is contained in:
Matthias Beyer 2017-12-03 20:48:54 +01:00
parent 72710323d0
commit b17772041f

View file

@ -81,7 +81,7 @@ impl<F: Fn(&FileLockEntry) -> Vec<String>> Lister for TableLister<F> {
}, },
} }
entries.fold(Ok(table), |table, entry| { entries.enumerate().fold(Ok(table), |table, (i, entry)| {
table.and_then(|mut table| { table.and_then(|mut table| {
let mut v = (self.line_generator)(&entry); let mut v = (self.line_generator)(&entry);
{ {
@ -97,6 +97,10 @@ impl<F: Fn(&FileLockEntry) -> Vec<String>> Lister for TableLister<F> {
} }
} }
if self.with_idx {
v.insert(0, format!("{}", i));
}
table.add_row(v.iter().map(|s| Cell::new(s)).collect()); table.add_row(v.iter().map(|s| Cell::new(s)).collect());
Ok(table) Ok(table)
}) })