From a272d3df16df67db0cd41df517b7d0379116ccee Mon Sep 17 00:00:00 2001 From: John Higgins Date: Fri, 9 Sep 2022 17:04:09 -0700 Subject: [PATCH] Added -S flag for truncating long lines --- src/bin/bat/app.rs | 23 ++++++++++++++--------- src/bin/bat/clap_app.rs | 7 +++++++ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 7bab26c3..b52aa265 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -161,17 +161,22 @@ impl App { }), show_nonprintable: self.matches.get_flag("show-all"), wrapping_mode: if self.interactive_output || maybe_term_width.is_some() { - match self.matches.get_one::("wrap").map(|s| s.as_str()) { - Some("character") => WrappingMode::Character, - Some("never") => WrappingMode::NoWrapping(true), - Some("auto") | None => { - if style_components.plain() { - WrappingMode::NoWrapping(false) - } else { - WrappingMode::Character + if !self.matches.contains_id("chop-long-lines") { + match self.matches.get_one::("wrap").map(|s| s.as_str()) { + Some("character") => WrappingMode::Character, + Some("never") => WrappingMode::NoWrapping(true), + Some("auto") | None => { + if style_components.plain() { + WrappingMode::NoWrapping(false) + } else { + WrappingMode::Character + } } + _ => unreachable!("other values for --wrap are not allowed"), } - _ => unreachable!("other values for --wrap are not allowed"), + } + else { + WrappingMode::NoWrapping(true) } } else { // We don't have the tty width when piping to another program. diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index f96e9e98..426f6171 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -201,6 +201,13 @@ pub fn build_app(interactive_output: bool) -> Command<'static> { The '--terminal-width' option can be used in addition to \ control the output width."), ) + .arg( + Arg::new("chop-long-lines") + .long("chop-long-lines") + .short('S') + .takes_value(false) + .help("Truncate all lines longer than screen width. Alias for '--wrap=never'."), + ) .arg( Arg::new("terminal-width") .long("terminal-width")