Merge branch 'extend-ui' into rewrite
This commit is contained in:
commit
16574abad1
1 changed files with 73 additions and 0 deletions
|
@ -23,6 +23,21 @@ pub trait FilePrinter {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_file_custom<F>(&self, file: Rc<RefCell<File>>, f: &F)
|
||||
where F: Fn(Rc<RefCell<File>>) -> String
|
||||
{
|
||||
info!("{}", f(file));
|
||||
}
|
||||
|
||||
fn print_files_custom<F, I>(&self, files: I, f: &F)
|
||||
where I: Iterator<Item = Rc<RefCell<File>>>,
|
||||
F: Fn(Rc<RefCell<File>>) -> String
|
||||
{
|
||||
for file in files {
|
||||
self.print_file_custom(file, f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct DebugPrinter {
|
||||
|
@ -43,6 +58,14 @@ impl FilePrinter for DebugPrinter {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_file_custom<F>(&self, file: Rc<RefCell<File>>, f: &F)
|
||||
where F: Fn(Rc<RefCell<File>>) -> String
|
||||
{
|
||||
if self.debug {
|
||||
debug!("[DebugPrinter] ->\n{:?}", f(file));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct SimplePrinter {
|
||||
|
@ -69,6 +92,19 @@ impl FilePrinter for SimplePrinter {
|
|||
}
|
||||
}
|
||||
|
||||
fn print_file_custom<F>(&self, file: Rc<RefCell<File>>, f: &F)
|
||||
where F: Fn(Rc<RefCell<File>>) -> String
|
||||
{
|
||||
let s = f(file);
|
||||
if self.debug {
|
||||
debug!("{:?}", s);
|
||||
} else if self.verbose {
|
||||
info!("{}", s);
|
||||
} else {
|
||||
info!("[File]: {}", s);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pub struct TablePrinter {
|
||||
|
@ -122,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 a new issue