From 1fde80800b41bcf7220624c67cdd7b9081f7310d Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 28 Dec 2015 14:20:34 +0100 Subject: [PATCH] Allow the custom function to return an Vec in the FilePrinter trait --- src/ui/file.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/ui/file.rs b/src/ui/file.rs index a45bb71e..d3bd4d0e 100644 --- a/src/ui/file.rs +++ b/src/ui/file.rs @@ -24,14 +24,14 @@ pub trait FilePrinter { } fn print_file_custom(&self, file: Rc>, f: &F) - where F: Fn(Rc>) -> String + where F: Fn(Rc>) -> Vec { - info!("{}", f(file)); + info!("{}", f(file).join(" ")); } fn print_files_custom(&self, files: I, f: &F) where I: Iterator>>, - F: Fn(Rc>) -> String + F: Fn(Rc>) -> Vec { for file in files { self.print_file_custom(file, f); @@ -59,10 +59,10 @@ impl FilePrinter for DebugPrinter { } fn print_file_custom(&self, file: Rc>, f: &F) - where F: Fn(Rc>) -> String + where F: Fn(Rc>) -> Vec { if self.debug { - debug!("[DebugPrinter] ->\n{:?}", f(file)); + debug!("[DebugPrinter] ->\n{:?}", f(file).join(" ")); } } @@ -93,9 +93,9 @@ impl FilePrinter for SimplePrinter { } fn print_file_custom(&self, file: Rc>, f: &F) - where F: Fn(Rc>) -> String + where F: Fn(Rc>) -> Vec { - let s = f(file); + let s = f(file).join(" "); if self.debug { debug!("{:?}", s); } else if self.verbose { @@ -160,7 +160,7 @@ impl FilePrinter for TablePrinter { fn print_files_custom(&self, files: I, f: &F) where I: Iterator>>, - F: Fn(Rc>) -> String + F: Fn(Rc>) -> Vec { use prettytable::Table; use prettytable::row::Row; @@ -181,9 +181,13 @@ impl FilePrinter for TablePrinter { let id : String = file.deref().borrow().id().clone().into(); let cell_id = Cell::new(&id[..]); - let cell_extra = Cell::new(&f(file)[..]); + let mut row = Row::new(vec![cell_i, cell_o, cell_id]); + + for cell in f(file).iter() { + debug!("Adding custom cell: {:?}", cell); + row.add_cell(Cell::new(&cell[..])) + } - let row = Row::new(vec![cell_i, cell_o, cell_id, cell_extra]); tab.add_row(row); }