Add StdoutViewer
This commit is contained in:
parent
b0e6c00f22
commit
98e0e5aaf5
2 changed files with 39 additions and 0 deletions
|
@ -1 +1,2 @@
|
|||
pub mod plain;
|
||||
pub mod stdout;
|
||||
|
|
38
libimagentryview/src/builtin/stdout.rs
Normal file
38
libimagentryview/src/builtin/stdout.rs
Normal 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(())
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue