Add feature to trim content on the right
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
0ba19daa57
commit
171b42307d
1 changed files with 15 additions and 2 deletions
|
@ -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)?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue