From e814977de1481b75afdebbc988e5b1cefd421ff3 Mon Sep 17 00:00:00 2001 From: eth-p <32112321+eth-p@users.noreply.github.com> Date: Fri, 7 Sep 2018 10:27:20 -0700 Subject: [PATCH 1/5] Wrapping disabled when --plain is used. (#289) --- src/app.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/app.rs b/src/app.rs index 0e61cc7d50..5ab023621e 100644 --- a/src/app.rs +++ b/src/app.rs @@ -190,10 +190,11 @@ impl App { .long("plain") .conflicts_with("style") .conflicts_with("number") - .help("Show plain style (alias for '--style=plain').") + .conflicts_with("wrap") + .help("Show plain style (alias for '--style=plain' and '--wrap=never').") .long_help( - "Only show plain style, no decorations. This is an alias for \ - '--style=plain'", + "Only show plain style, no decorations, no wrapping. This is an alias for \ + '--style=plain' and '--wrap=never'", ), ).arg( Arg::with_name("number") @@ -348,6 +349,9 @@ impl App { // We don't have the tty width when piping to another program. // There's no point in wrapping when this is the case. OutputWrap::None + } else if self.matches.is_present("plain") { + // No point in wrapping when it's plain. + OutputWrap::None } else { match self.matches.value_of("wrap") { Some("character") => OutputWrap::Character, @@ -379,8 +383,7 @@ impl App { } }, }, - term_width: self - .matches + term_width: self.matches .value_of("terminal-width") .and_then(|w| w.parse().ok()) .unwrap_or(Term::stdout().size().1 as usize), @@ -388,8 +391,7 @@ impl App { || self.matches.value_of("color") == Some("always") || self.matches.value_of("decorations") == Some("always")), files, - theme: self - .matches + theme: self.matches .value_of("theme") .map(String::from) .or_else(|| env::var("BAT_THEME").ok()) @@ -409,8 +411,10 @@ impl App { } else { InputFile::Ordinary(filename) } - }).collect() - }).unwrap_or_else(|| vec![InputFile::StdIn]) + }) + .collect() + }) + .unwrap_or_else(|| vec![InputFile::StdIn]) } fn output_components(&self) -> Result { From ad94a272b92328ad8fe03d366a742539165c7eab Mon Sep 17 00:00:00 2001 From: eth-p <32112321+eth-p@users.noreply.github.com> Date: Fri, 7 Sep 2018 10:51:47 -0700 Subject: [PATCH 2/5] Automatically disable wrapping when style is plain. --- src/app.rs | 24 +++++++++++++----------- src/style.rs | 4 ++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/app.rs b/src/app.rs index 5ab023621e..0dc239fd50 100644 --- a/src/app.rs +++ b/src/app.rs @@ -190,11 +190,10 @@ impl App { .long("plain") .conflicts_with("style") .conflicts_with("number") - .conflicts_with("wrap") - .help("Show plain style (alias for '--style=plain' and '--wrap=never').") + .help("Show plain style (alias for '--style=plain'.") .long_help( - "Only show plain style, no decorations, no wrapping. This is an alias for \ - '--style=plain' and '--wrap=never'", + "Only show plain style, no decorations. This is an alias for \ + '--style=plain'", ), ).arg( Arg::with_name("number") @@ -264,8 +263,8 @@ impl App { .overrides_with("wrap") .takes_value(true) .value_name("mode") - .possible_values(&["character", "never"]) - .default_value("character") + .possible_values(&["auto", "never", "character"]) + .default_value("auto") .help("Specify the text-wrapping mode.") .long_help("Specify the text-wrapping mode."), ).arg( @@ -340,22 +339,24 @@ impl App { pub fn config(&self) -> Result { let files = self.files(); + let output_components = self.output_components()?; Ok(Config { true_color: is_truecolor_terminal(), - output_components: self.output_components()?, language: self.matches.value_of("language"), output_wrap: if !self.interactive_output { // We don't have the tty width when piping to another program. // There's no point in wrapping when this is the case. OutputWrap::None - } else if self.matches.is_present("plain") { - // No point in wrapping when it's plain. - OutputWrap::None } else { match self.matches.value_of("wrap") { Some("character") => OutputWrap::Character, - Some("never") | _ => OutputWrap::None, + Some("never") => OutputWrap::None, + Some("auto") | _ => if output_components.plain() { + OutputWrap::None + } else { + OutputWrap::Character + }, } }, colored_output: match self.matches.value_of("color") { @@ -397,6 +398,7 @@ impl App { .or_else(|| env::var("BAT_THEME").ok()) .unwrap_or(String::from(BAT_THEME_DEFAULT)), line_range: transpose(self.matches.value_of("line-range").map(LineRange::from))?, + output_components, }) } diff --git a/src/style.rs b/src/style.rs index 4c36265d17..efd83697b1 100644 --- a/src/style.rs +++ b/src/style.rs @@ -78,4 +78,8 @@ impl OutputComponents { pub fn numbers(&self) -> bool { self.0.contains(&OutputComponent::Numbers) } + + pub fn plain(&self) -> bool { + self.0.is_empty() + } } From 13c15e15a87bf0927f1071a86a4b72d5c67d2cff Mon Sep 17 00:00:00 2001 From: eth-p <32112321+eth-p@users.noreply.github.com> Date: Fri, 7 Sep 2018 10:56:59 -0700 Subject: [PATCH 3/5] Typo --- src/app.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index 0dc239fd50..8be7c18452 100644 --- a/src/app.rs +++ b/src/app.rs @@ -190,7 +190,7 @@ impl App { .long("plain") .conflicts_with("style") .conflicts_with("number") - .help("Show plain style (alias for '--style=plain'.") + .help("Show plain style (alias for '--style=plain').") .long_help( "Only show plain style, no decorations. This is an alias for \ '--style=plain'", From 1ed9d208d1f0b87bf7f725bd4999450b70be8c4b Mon Sep 17 00:00:00 2001 From: eth-p <32112321+eth-p@users.noreply.github.com> Date: Fri, 7 Sep 2018 11:13:03 -0700 Subject: [PATCH 4/5] Formatted for newest rustfmt. --- src/app.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app.rs b/src/app.rs index 8be7c18452..9af36bca2c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -384,7 +384,8 @@ impl App { } }, }, - term_width: self.matches + term_width: self + .matches .value_of("terminal-width") .and_then(|w| w.parse().ok()) .unwrap_or(Term::stdout().size().1 as usize), @@ -392,7 +393,8 @@ impl App { || self.matches.value_of("color") == Some("always") || self.matches.value_of("decorations") == Some("always")), files, - theme: self.matches + theme: self + .matches .value_of("theme") .map(String::from) .or_else(|| env::var("BAT_THEME").ok()) From 41454caa7df0b91c23d8c479c155e7d6b53b200d Mon Sep 17 00:00:00 2001 From: sharkdp Date: Fri, 7 Sep 2018 21:50:47 +0200 Subject: [PATCH 5/5] Run 'cargo fmt' --- src/app.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/app.rs b/src/app.rs index 9af36bca2c..a9ac691e13 100644 --- a/src/app.rs +++ b/src/app.rs @@ -415,10 +415,8 @@ impl App { } else { InputFile::Ordinary(filename) } - }) - .collect() - }) - .unwrap_or_else(|| vec![InputFile::StdIn]) + }).collect() + }).unwrap_or_else(|| vec![InputFile::StdIn]) } fn output_components(&self) -> Result {