Merge pull request #1165 from matthiasbeyer/libimagentrylist/with-idx-fix

TableLister: If configured with index, also print index row
This commit is contained in:
Matthias Beyer 2017-12-03 22:23:44 +01:00 committed by GitHub
commit b1cf058dcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

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| {
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());
Ok(table)
})