Add StdoutViewer

This commit is contained in:
Matthias Beyer 2016-07-16 22:46:43 +02:00
parent b0e6c00f22
commit 98e0e5aaf5
2 changed files with 39 additions and 0 deletions

View file

@ -1 +1,2 @@
pub mod plain;
pub mod stdout;

View file

@ -0,0 +1,38 @@
use libimagstore::store::Entry;
use toml::encode_str;
use viewer::Viewer;
use result::Result;
pub struct StdoutViewer {
view_header: bool,
view_content: bool,
}
impl StdoutViewer {
pub fn new(view_header: bool, view_content: bool) -> StdoutViewer {
StdoutViewer {
view_header: view_header,
view_content: view_content,
}
}
}
impl Viewer for StdoutViewer {
fn view_entry(&self, e: &Entry) -> Result<()> {
if self.view_header {
println!("{}", encode_str(e.get_header().header()));
}
if self.view_content {
println!("{}", e.get_content());
}
Ok(())
}
}