diff --git a/bin/core/imag-view/Cargo.toml b/bin/core/imag-view/Cargo.toml index 62442744..3e4c5125 100644 --- a/bin/core/imag-view/Cargo.toml +++ b/bin/core/imag-view/Cargo.toml @@ -32,6 +32,7 @@ libimagstore = { version = "0.8.0", path = "../../../lib/core/libimagstore" libimagrt = { version = "0.8.0", path = "../../../lib/core/libimagrt" } libimagerror = { version = "0.8.0", path = "../../../lib/core/libimagerror" } libimagentryview = { version = "0.8.0", path = "../../../lib/entry/libimagentryview" } +libimagutil = { version = "0.8.0", path = "../../../lib/etc/libimagutil" } [dependencies.clap] version = "^2.29" diff --git a/bin/core/imag-view/src/main.rs b/bin/core/imag-view/src/main.rs index 0e5b29b6..e8241be6 100644 --- a/bin/core/imag-view/src/main.rs +++ b/bin/core/imag-view/src/main.rs @@ -43,7 +43,9 @@ extern crate libimagentryview; extern crate libimagerror; #[macro_use] extern crate libimagrt; extern crate libimagstore; +extern crate libimagutil; +use std::str::FromStr; use std::collections::BTreeMap; use std::io::Write; use std::io::Read; @@ -82,7 +84,6 @@ fn main() { let view_header = rt.cli().is_present("view-header"); let hide_content = rt.cli().is_present("not-view-content"); - if rt.cli().is_present("in") { let files = entry_ids .into_iter() @@ -170,7 +171,19 @@ fn main() { drop(files); } else { - let viewer = StdoutViewer::new(view_header, !hide_content); + let mut viewer = StdoutViewer::new(view_header, !hide_content); + + if rt.cli().is_present("autowrap") { + let width = rt.cli().value_of("autowrap").unwrap(); // ensured by clap + let width = usize::from_str(width).unwrap_or_else(|e| { + error!("Failed to parse argument to number: autowrap = {:?}", + rt.cli().value_of("autowrap").map(String::from)); + error!("-> {:?}", e); + ::std::process::exit(1) + }); + + viewer.wrap_at(width); + } entry_ids .into_iter() diff --git a/bin/core/imag-view/src/ui.rs b/bin/core/imag-view/src/ui.rs index ef0be8a1..7dbc9696 100644 --- a/bin/core/imag-view/src/ui.rs +++ b/bin/core/imag-view/src/ui.rs @@ -40,6 +40,17 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { .args(&["id", "entries-from-stdin"]) .required(true)) + .arg(Arg::with_name("autowrap") + .long("autowrap") + .short("w") + .takes_value(true) + .required(false) + .multiple(false) + .value_name("WIDTH") + .default_value("80") + .validator(::libimagutil::cli_validators::is_integer) + .help("Automatically wrap long lines. Has only an effect when using stdout as output.")) + .arg(Arg::with_name("view-header") .long("header") .short("h")