Add wrapping functionality to StdoutViewer
This commit is contained in:
parent
bed49b6ece
commit
91a72709f8
3 changed files with 14 additions and 1 deletions
|
@ -23,6 +23,7 @@ maintenance = { status = "actively-developed" }
|
||||||
log = "0.4.0"
|
log = "0.4.0"
|
||||||
toml = "0.4"
|
toml = "0.4"
|
||||||
error-chain = "0.11"
|
error-chain = "0.11"
|
||||||
|
textwrap = "0.9"
|
||||||
|
|
||||||
libimagrt = { version = "0.8.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.8.0", path = "../../../lib/core/libimagrt" }
|
||||||
libimagstore = { version = "0.8.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.8.0", path = "../../../lib/core/libimagstore" }
|
||||||
|
|
|
@ -27,6 +27,7 @@ use error::Result;
|
||||||
pub struct StdoutViewer {
|
pub struct StdoutViewer {
|
||||||
view_header: bool,
|
view_header: bool,
|
||||||
view_content: bool,
|
view_content: bool,
|
||||||
|
wrap_content: Option<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StdoutViewer {
|
impl StdoutViewer {
|
||||||
|
@ -35,9 +36,14 @@ impl StdoutViewer {
|
||||||
StdoutViewer {
|
StdoutViewer {
|
||||||
view_header: view_header,
|
view_header: view_header,
|
||||||
view_content: view_content,
|
view_content: view_content,
|
||||||
|
wrap_content: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn wrap_at(&mut self, wrap: usize) {
|
||||||
|
self.wrap_content = Some(wrap)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Viewer for StdoutViewer {
|
impl Viewer for StdoutViewer {
|
||||||
|
@ -48,7 +54,12 @@ impl Viewer for StdoutViewer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.view_content {
|
if self.view_content {
|
||||||
println!("{}", e.get_content());
|
match self.wrap_content {
|
||||||
|
Some(limit) => ::textwrap::wrap(e.get_content(), limit).iter().for_each(|line| {
|
||||||
|
println!("{}", line)
|
||||||
|
}),
|
||||||
|
None => println!("{}", e.get_content()),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
|
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
#[macro_use] extern crate error_chain;
|
#[macro_use] extern crate error_chain;
|
||||||
|
extern crate textwrap;
|
||||||
|
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
extern crate libimagrt;
|
extern crate libimagrt;
|
||||||
|
|
Loading…
Reference in a new issue