Add feature to trim content on the right

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-02-06 01:05:43 +01:00
parent 0ba19daa57
commit 171b42307d
1 changed files with 15 additions and 2 deletions

View File

@ -29,6 +29,7 @@ use failure::Fallible as Result;
pub struct StdoutViewer { pub struct StdoutViewer {
view_header: bool, view_header: bool,
view_content: bool, view_content: bool,
trim_right: bool,
wrap_content: Option<usize>, wrap_content: Option<usize>,
} }
@ -38,6 +39,7 @@ impl StdoutViewer {
StdoutViewer { StdoutViewer {
view_header: view_header, view_header: view_header,
view_content: view_content, view_content: view_content,
trim_right: false,
wrap_content: None, wrap_content: None,
} }
} }
@ -46,6 +48,10 @@ impl StdoutViewer {
self.wrap_content = Some(wrap) self.wrap_content = Some(wrap)
} }
pub fn trim_right(&mut self, trim: bool) {
self.trim_right = trim;
}
} }
impl Viewer for StdoutViewer { impl Viewer for StdoutViewer {
@ -59,11 +65,18 @@ impl Viewer for StdoutViewer {
} }
if self.view_content { if self.view_content {
let content = if self.trim_right {
e.get_content().trim_right()
} else {
&e.get_content()
};
match self.wrap_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)?; let _ = writeln!(sink, "{}", line)?;
}, },
None => writeln!(sink, "{}", e.get_content())?, None => writeln!(sink, "{}", content)?,
} }
} }