Impl FilePrinter for TablePrinter ::print_files_custom()
This commit is contained in:
parent
6455c45630
commit
51605e1314
|
@ -158,4 +158,41 @@ impl FilePrinter for TablePrinter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn print_files_custom<F, I>(&self, files: I, f: &F)
|
||||||
|
where I: Iterator<Item = Rc<RefCell<File>>>,
|
||||||
|
F: Fn(Rc<RefCell<File>>) -> String
|
||||||
|
{
|
||||||
|
use prettytable::Table;
|
||||||
|
use prettytable::row::Row;
|
||||||
|
use prettytable::cell::Cell;
|
||||||
|
|
||||||
|
let titles = row!["File#", "Owner", "ID", "..."];
|
||||||
|
|
||||||
|
let mut tab = Table::new();
|
||||||
|
tab.set_titles(titles);
|
||||||
|
|
||||||
|
let mut i = 0;
|
||||||
|
for file in files {
|
||||||
|
debug!("Printing file: {:?}", file);
|
||||||
|
i += 1;
|
||||||
|
let cell_i = Cell::new(&format!("{}", i)[..]);
|
||||||
|
let cell_o = Cell::new(&format!("{}", file.deref().borrow().owner_name())[..]);
|
||||||
|
|
||||||
|
let id : String = file.deref().borrow().id().clone().into();
|
||||||
|
let cell_id = Cell::new(&id[..]);
|
||||||
|
|
||||||
|
let cell_extra = Cell::new(&f(file)[..]);
|
||||||
|
|
||||||
|
let row = Row::new(vec![cell_i, cell_o, cell_id, cell_extra]);
|
||||||
|
tab.add_row(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
if i != 0 {
|
||||||
|
debug!("Printing {} table entries", i);
|
||||||
|
tab.printstd();
|
||||||
|
} else {
|
||||||
|
debug!("Not printing table because there are zero entries");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue