diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-02-06 01:05:43 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-02-11 03:52:04 +0100 |
commit | 171b42307d872bad92d034e85f195307e4676481 (patch) | |
tree | 4688d9e5d0a059bf75e9ebc9160df556bbc51c3e | |
parent | 0ba19daa578112fd6bd39d8b163d506d7815b7b5 (diff) |
Add feature to trim content on the right
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | lib/entry/libimagentryview/src/builtin/stdout.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/entry/libimagentryview/src/builtin/stdout.rs b/lib/entry/libimagentryview/src/builtin/stdout.rs index d84c192d..a2762d04 100644 --- a/lib/entry/libimagentryview/src/builtin/stdout.rs +++ b/lib/entry/libimagentryview/src/builtin/stdout.rs @@ -29,6 +29,7 @@ use failure::Fallible as Result; pub struct StdoutViewer { view_header: bool, view_content: bool, + trim_right: bool, wrap_content: Option<usize>, } @@ -38,6 +39,7 @@ impl StdoutViewer { StdoutViewer { view_header: view_header, view_content: view_content, + trim_right: false, wrap_content: None, } } @@ -46,6 +48,10 @@ impl StdoutViewer { self.wrap_content = Some(wrap) } + pub fn trim_right(&mut self, trim: bool) { + self.trim_right = trim; + } + } impl Viewer for StdoutViewer { @@ -59,11 +65,18 @@ impl Viewer for StdoutViewer { } if self.view_content { + let content = if self.trim_right { + e.get_content().trim_right() + } else { + &e.get_content() + }; + match self.wrap_content { - Some(limit) => for line in ::textwrap::wrap(e.get_content(), limit).iter() { + + Some(limit) => for line in ::textwrap::wrap(content, limit).iter() { let _ = writeln!(sink, "{}", line)?; }, - None => writeln!(sink, "{}", e.get_content())?, + None => writeln!(sink, "{}", content)?, } } |