Auto merge of #67 - matthiasbeyer:tableprinter-pretty, r=matthiasbeyer
Tableprinter pretty Support for printing plain ASCII-Tables without borders and such.
This commit is contained in:
commit
72f7254005
4 changed files with 58 additions and 16 deletions
12
etc/cli.yml
12
etc/cli.yml
|
@ -96,6 +96,12 @@ subcommands:
|
|||
version: 0.1
|
||||
author: Matthias Beyer <mail@beyermatthias.de>
|
||||
args:
|
||||
- pretty:
|
||||
long: pretty
|
||||
help: Print table with ASCII-border
|
||||
required: false
|
||||
takes_value: false
|
||||
|
||||
- match:
|
||||
short: m
|
||||
long: match
|
||||
|
@ -402,6 +408,12 @@ subcommands:
|
|||
version: 0.1
|
||||
author: Matthias Beyer <mail@beyermatthias.de>
|
||||
args:
|
||||
- pretty:
|
||||
long: pretty
|
||||
help: Print table with ASCII-border
|
||||
required: false
|
||||
takes_value: false
|
||||
|
||||
- namegrep:
|
||||
short: n
|
||||
long: name
|
||||
|
|
|
@ -130,7 +130,8 @@ impl<'a> BM<'a> {
|
|||
.load_for_module(self, &self.parser)
|
||||
.into_iter()
|
||||
.filter(|file| filter.filter_file(file));
|
||||
let printer = TablePrinter::new(self.rt.is_verbose(), self.rt.is_debugging());
|
||||
let pretty = matches.is_present("pretty");
|
||||
let printer = TablePrinter::new(self.rt.is_verbose(), self.rt.is_debugging(), pretty);
|
||||
|
||||
printer.print_files_custom(files,
|
||||
&|file| {
|
||||
|
|
|
@ -274,7 +274,9 @@ impl<'a> Notes<'a> {
|
|||
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 pretty = matches.is_present("pretty");
|
||||
debug!("Printing pretty table = {}", pretty);
|
||||
let printer = TablePrinter::new(self.rt.is_verbose(), self.rt.is_debugging(), pretty);
|
||||
|
||||
printer.print_files_custom(
|
||||
self.rt.store()
|
||||
|
@ -299,7 +301,6 @@ impl<'a> Notes<'a> {
|
|||
fn command_links(&self, matches: &ArgMatches) -> bool {
|
||||
use ansi_term::Colour::{Red, Green};
|
||||
use module::helpers::content::markdown::MarkdownParser;
|
||||
use ui::file::FilePrinter;
|
||||
use util::is_url;
|
||||
use prettytable::Table;
|
||||
use prettytable::row::Row;
|
||||
|
|
|
@ -10,8 +10,6 @@ use storage::file::File;
|
|||
*/
|
||||
pub trait FilePrinter {
|
||||
|
||||
fn new(verbose: bool, debug: bool) -> Self;
|
||||
|
||||
/*
|
||||
* Print a single file
|
||||
*/
|
||||
|
@ -50,14 +48,18 @@ struct DebugPrinter {
|
|||
debug: bool,
|
||||
}
|
||||
|
||||
impl FilePrinter for DebugPrinter {
|
||||
impl DebugPrinter {
|
||||
|
||||
fn new(_: bool, debug: bool) -> DebugPrinter {
|
||||
pub fn new(debug: bool) -> DebugPrinter {
|
||||
DebugPrinter {
|
||||
debug: debug,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl FilePrinter for DebugPrinter {
|
||||
|
||||
fn print_file(&self, f: Rc<RefCell<File>>) {
|
||||
if self.debug {
|
||||
debug!("[DebugPrinter] ->\n{:?}", f);
|
||||
|
@ -82,15 +84,19 @@ struct SimplePrinter {
|
|||
debug: bool,
|
||||
}
|
||||
|
||||
impl FilePrinter for SimplePrinter {
|
||||
impl SimplePrinter {
|
||||
|
||||
fn new(verbose: bool, debug: bool) -> SimplePrinter {
|
||||
pub fn new(verbose: bool, debug: bool) -> SimplePrinter {
|
||||
SimplePrinter {
|
||||
debug: debug,
|
||||
verbose: verbose,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl FilePrinter for SimplePrinter {
|
||||
|
||||
fn print_file(&self, f: Rc<RefCell<File>>) {
|
||||
use ansi_term::Colour::Cyan;
|
||||
|
||||
|
@ -124,29 +130,43 @@ impl FilePrinter for SimplePrinter {
|
|||
* Table printer to print file information in a nice ASCII-table
|
||||
*/
|
||||
pub struct TablePrinter {
|
||||
sp: SimplePrinter,
|
||||
sp: SimplePrinter,
|
||||
pretty: bool,
|
||||
}
|
||||
|
||||
impl TablePrinter {
|
||||
|
||||
pub fn new(verbose: bool, debug: bool, pretty: bool) -> TablePrinter {
|
||||
TablePrinter {
|
||||
sp: SimplePrinter::new(verbose, debug),
|
||||
pretty: pretty,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl FilePrinter for TablePrinter {
|
||||
|
||||
fn new(verbose: bool, debug: bool) -> TablePrinter {
|
||||
TablePrinter {
|
||||
sp: SimplePrinter::new(verbose, debug),
|
||||
}
|
||||
}
|
||||
|
||||
fn print_file(&self, f: Rc<RefCell<File>>) {
|
||||
self.sp.print_file(f);
|
||||
}
|
||||
|
||||
fn print_files<I: Iterator<Item = Rc<RefCell<File>>>>(&self, files: I) {
|
||||
use prettytable::Table;
|
||||
use prettytable::format::TableFormat;
|
||||
use prettytable::row::Row;
|
||||
use prettytable::cell::Cell;
|
||||
|
||||
let titles = row!["File#", "Owner", "ID"];
|
||||
|
||||
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);
|
||||
|
||||
let mut i = 0;
|
||||
|
@ -175,12 +195,20 @@ impl FilePrinter for TablePrinter {
|
|||
F: Fn(Rc<RefCell<File>>) -> Vec<String>
|
||||
{
|
||||
use prettytable::Table;
|
||||
use prettytable::format::TableFormat;
|
||||
use prettytable::row::Row;
|
||||
use prettytable::cell::Cell;
|
||||
|
||||
let titles = row!["#", "Module", "ID", "..."];
|
||||
|
||||
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);
|
||||
|
||||
let mut i = 0;
|
||||
|
|
Loading…
Reference in a new issue