From 98e0e5aaf54474770cea9dcf6dde10c1f0b88e20 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 16 Jul 2016 22:46:43 +0200 Subject: [PATCH] Add StdoutViewer --- libimagentryview/src/builtin/mod.rs | 1 + libimagentryview/src/builtin/stdout.rs | 38 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 libimagentryview/src/builtin/stdout.rs diff --git a/libimagentryview/src/builtin/mod.rs b/libimagentryview/src/builtin/mod.rs index 6c83de88..248d8b25 100644 --- a/libimagentryview/src/builtin/mod.rs +++ b/libimagentryview/src/builtin/mod.rs @@ -1 +1,2 @@ pub mod plain; +pub mod stdout; diff --git a/libimagentryview/src/builtin/stdout.rs b/libimagentryview/src/builtin/stdout.rs new file mode 100644 index 00000000..7f6a8b28 --- /dev/null +++ b/libimagentryview/src/builtin/stdout.rs @@ -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(()) + } + +}