Move ::new() out of FilePrinter trait

This commit is contained in:
Matthias Beyer 2016-01-06 19:31:20 +01:00
parent aaf3660f31
commit 71f37f69c3
2 changed files with 19 additions and 10 deletions

View file

@ -299,7 +299,6 @@ impl<'a> Notes<'a> {
fn command_links(&self, matches: &ArgMatches) -> bool { fn command_links(&self, matches: &ArgMatches) -> bool {
use ansi_term::Colour::{Red, Green}; use ansi_term::Colour::{Red, Green};
use module::helpers::content::markdown::MarkdownParser; use module::helpers::content::markdown::MarkdownParser;
use ui::file::FilePrinter;
use util::is_url; use util::is_url;
use prettytable::Table; use prettytable::Table;
use prettytable::row::Row; use prettytable::row::Row;

View file

@ -10,8 +10,6 @@ use storage::file::File;
*/ */
pub trait FilePrinter { pub trait FilePrinter {
fn new(verbose: bool, debug: bool) -> Self;
/* /*
* Print a single file * Print a single file
*/ */
@ -50,14 +48,18 @@ struct DebugPrinter {
debug: bool, debug: bool,
} }
impl FilePrinter for DebugPrinter { impl DebugPrinter {
fn new(_: bool, debug: bool) -> DebugPrinter { pub fn new(debug: bool) -> DebugPrinter {
DebugPrinter { DebugPrinter {
debug: debug, debug: debug,
} }
} }
}
impl FilePrinter for DebugPrinter {
fn print_file(&self, f: Rc<RefCell<File>>) { fn print_file(&self, f: Rc<RefCell<File>>) {
if self.debug { if self.debug {
debug!("[DebugPrinter] ->\n{:?}", f); debug!("[DebugPrinter] ->\n{:?}", f);
@ -82,15 +84,19 @@ struct SimplePrinter {
debug: bool, debug: bool,
} }
impl FilePrinter for SimplePrinter { impl SimplePrinter {
fn new(verbose: bool, debug: bool) -> SimplePrinter { pub fn new(verbose: bool, debug: bool) -> SimplePrinter {
SimplePrinter { SimplePrinter {
debug: debug, debug: debug,
verbose: verbose, verbose: verbose,
} }
} }
}
impl FilePrinter for SimplePrinter {
fn print_file(&self, f: Rc<RefCell<File>>) { fn print_file(&self, f: Rc<RefCell<File>>) {
use ansi_term::Colour::Cyan; use ansi_term::Colour::Cyan;
@ -127,14 +133,18 @@ pub struct TablePrinter {
sp: SimplePrinter, sp: SimplePrinter,
} }
impl FilePrinter for TablePrinter { impl TablePrinter {
fn new(verbose: bool, debug: bool) -> TablePrinter { pub fn new(verbose: bool, debug: bool) -> TablePrinter {
TablePrinter { TablePrinter {
sp: SimplePrinter::new(verbose, debug), sp: SimplePrinter::new(verbose, debug),
} }
} }
}
impl FilePrinter for TablePrinter {
fn print_file(&self, f: Rc<RefCell<File>>) { fn print_file(&self, f: Rc<RefCell<File>>) {
self.sp.print_file(f); self.sp.print_file(f);
} }