Add support for printing table without borders

This commit is contained in:
Matthias Beyer 2016-01-06 19:37:52 +01:00
parent 71f37f69c3
commit 56730cb7b8
3 changed files with 22 additions and 4 deletions

View file

@ -130,7 +130,7 @@ impl<'a> BM<'a> {
.load_for_module(self, &self.parser) .load_for_module(self, &self.parser)
.into_iter() .into_iter()
.filter(|file| filter.filter_file(file)); .filter(|file| filter.filter_file(file));
let printer = TablePrinter::new(self.rt.is_verbose(), self.rt.is_debugging()); let printer = TablePrinter::new(self.rt.is_verbose(), self.rt.is_debugging(), true);
printer.print_files_custom(files, printer.print_files_custom(files,
&|file| { &|file| {

View file

@ -274,7 +274,7 @@ impl<'a> Notes<'a> {
hash_filter.or(Box::new(head_filter)).and(Box::new(text_filter)).and(Box::new(tags_filter)) hash_filter.or(Box::new(head_filter)).and(Box::new(text_filter)).and(Box::new(tags_filter))
}; };
let printer = TablePrinter::new(self.rt.is_verbose(), self.rt.is_debugging()); let printer = TablePrinter::new(self.rt.is_verbose(), self.rt.is_debugging(), true);
printer.print_files_custom( printer.print_files_custom(
self.rt.store() self.rt.store()

View file

@ -130,14 +130,16 @@ impl FilePrinter for SimplePrinter {
* Table printer to print file information in a nice ASCII-table * Table printer to print file information in a nice ASCII-table
*/ */
pub struct TablePrinter { pub struct TablePrinter {
sp: SimplePrinter, sp: SimplePrinter,
pretty: bool,
} }
impl TablePrinter { impl TablePrinter {
pub fn new(verbose: bool, debug: bool) -> TablePrinter { pub fn new(verbose: bool, debug: bool, pretty: bool) -> TablePrinter {
TablePrinter { TablePrinter {
sp: SimplePrinter::new(verbose, debug), sp: SimplePrinter::new(verbose, debug),
pretty: pretty,
} }
} }
@ -151,12 +153,20 @@ impl FilePrinter for TablePrinter {
fn print_files<I: Iterator<Item = Rc<RefCell<File>>>>(&self, files: I) { fn print_files<I: Iterator<Item = Rc<RefCell<File>>>>(&self, files: I) {
use prettytable::Table; use prettytable::Table;
use prettytable::format::TableFormat;
use prettytable::row::Row; use prettytable::row::Row;
use prettytable::cell::Cell; use prettytable::cell::Cell;
let titles = row!["File#", "Owner", "ID"]; let titles = row!["File#", "Owner", "ID"];
let mut tab = Table::new(); let mut tab = Table::new();
if !self.pretty {
let plain_format = TableFormat::new(' ', None, None);
debug!("Setting plain format for table");
tab.set_format(plain_format);
}
tab.set_titles(titles); tab.set_titles(titles);
let mut i = 0; let mut i = 0;
@ -185,12 +195,20 @@ impl FilePrinter for TablePrinter {
F: Fn(Rc<RefCell<File>>) -> Vec<String> F: Fn(Rc<RefCell<File>>) -> Vec<String>
{ {
use prettytable::Table; use prettytable::Table;
use prettytable::format::TableFormat;
use prettytable::row::Row; use prettytable::row::Row;
use prettytable::cell::Cell; use prettytable::cell::Cell;
let titles = row!["#", "Module", "ID", "..."]; let titles = row!["#", "Module", "ID", "..."];
let mut tab = Table::new(); let mut tab = Table::new();
if !self.pretty {
let plain_format = TableFormat::new(' ', None, None);
debug!("Setting plain format for table");
tab.set_format(plain_format);
}
tab.set_titles(titles); tab.set_titles(titles);
let mut i = 0; let mut i = 0;