From 60c124fb9d0c87fc7e50b4001d90b381d435eac3 Mon Sep 17 00:00:00 2001 From: Alexander Karlis Date: Sat, 15 Aug 2020 23:12:33 -0400 Subject: [PATCH 1/6] Added new alias for 'decoration=always' --- src/bin/bat/app.rs | 3 ++- src/bin/bat/clap_app.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 6c61215e67..bb74b87396 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -174,7 +174,8 @@ impl App { term_width: maybe_term_width.unwrap_or(Term::stdout().size().1 as usize), loop_through: !(self.interactive_output || self.matches.value_of("color") == Some("always") - || self.matches.value_of("decorations") == Some("always")), + || (self.matches.value_of("decorations") == Some("always") + || self.matches.is_present("always-decorations"))), tab_width: self .matches .value_of("tabs") diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index aa032a525b..eed59a5431 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -257,6 +257,15 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { an interactive terminal is detected. Possible values: *auto*, never, always.", ), ) + .arg( + Arg::with_name("always-decorations") + .short("D") + .alias("always-decor") + .overrides_with("always-decorations") + .hidden(true) + .hidden_short_help(true) + .help("Alias for '--decorations=always'") + ) .arg( Arg::with_name("paging") .long("paging") From 51834793bed0a39287d626ddcf57790fa91d2dc5 Mon Sep 17 00:00:00 2001 From: Alexander Karlis Date: Mon, 31 Aug 2020 21:58:20 -0400 Subject: [PATCH 2/6] added additional alias for color=always when always-decorations flag is triggered --- src/bin/bat/app.rs | 14 +++++++++----- src/bin/bat/clap_app.rs | 4 ++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index bb74b87396..0858f6aa5c 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -165,11 +165,14 @@ impl App { // There's no point in wrapping when this is the case. WrappingMode::NoWrapping }, - colored_output: match self.matches.value_of("color") { - Some("always") => true, - Some("never") => false, - Some("auto") | _ => env::var_os("NO_COLOR").is_none() && self.interactive_output, - }, + colored_output: self.matches.is_present("always-decorations") + || match self.matches.value_of("color") { + Some("always") => true, + Some("never") => false, + Some("auto") | _ => { + env::var_os("NO_COLOR").is_none() && self.interactive_output + } + }, paging_mode, term_width: maybe_term_width.unwrap_or(Term::stdout().size().1 as usize), loop_through: !(self.interactive_output @@ -285,6 +288,7 @@ impl App { fn style_components(&self) -> Result { let matches = &self.matches; + println!("{:#?}", matches); Ok(StyleComponents( if matches.value_of("decorations") == Some("never") { HashSet::new() diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index eed59a5431..f6775ab5fe 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -259,12 +259,12 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { ) .arg( Arg::with_name("always-decorations") - .short("D") + .short("f") .alias("always-decor") .overrides_with("always-decorations") .hidden(true) .hidden_short_help(true) - .help("Alias for '--decorations=always'") + .help("Alias for '--decorations=always --color=always'") ) .arg( Arg::with_name("paging") From a04de7ea1eddf1425b2197b08a9b2f1797a16218 Mon Sep 17 00:00:00 2001 From: Alexander Karlis Date: Mon, 31 Aug 2020 22:00:22 -0400 Subject: [PATCH 3/6] remove println --- src/bin/bat/app.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 0858f6aa5c..24cc7ac81e 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -288,7 +288,6 @@ impl App { fn style_components(&self) -> Result { let matches = &self.matches; - println!("{:#?}", matches); Ok(StyleComponents( if matches.value_of("decorations") == Some("never") { HashSet::new() From 4b7f48f0a8a76f91fc1276c150c764fd004a9706 Mon Sep 17 00:00:00 2001 From: Alexander Karlis Date: Fri, 11 Sep 2020 22:54:47 -0400 Subject: [PATCH 4/6] updated PR based on comments --- src/bin/bat/app.rs | 5 +++-- src/bin/bat/clap_app.rs | 13 ++++++++----- src/bin/bat/main.rs | 3 +++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 24cc7ac81e..9e4d0f75ad 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -165,7 +165,7 @@ impl App { // There's no point in wrapping when this is the case. WrappingMode::NoWrapping }, - colored_output: self.matches.is_present("always-decorations") + colored_output: self.matches.is_present("force-colorization") || match self.matches.value_of("color") { Some("always") => true, Some("never") => false, @@ -178,7 +178,7 @@ impl App { loop_through: !(self.interactive_output || self.matches.value_of("color") == Some("always") || (self.matches.value_of("decorations") == Some("always") - || self.matches.is_present("always-decorations"))), + || self.matches.is_present("force-colorization"))), tab_width: self .matches .value_of("tabs") @@ -288,6 +288,7 @@ impl App { fn style_components(&self) -> Result { let matches = &self.matches; + println!("{:#?}", matches); Ok(StyleComponents( if matches.value_of("decorations") == Some("never") { HashSet::new() diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index f6775ab5fe..385d017b88 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -258,13 +258,16 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { ), ) .arg( - Arg::with_name("always-decorations") + Arg::with_name("force-colorization") + .long("force-colorization") .short("f") - .alias("always-decor") - .overrides_with("always-decorations") - .hidden(true) + .conflicts_with("color") + .conflicts_with("decorations") + .overrides_with("force-colorization") .hidden_short_help(true) - .help("Alias for '--decorations=always --color=always'") + .long_help("Alias for '--decorations=always --color=always'. This is useful \ + if the output of bat is piped to another program, but you want \ + to keep the colorization/decorations.") ) .arg( Arg::with_name("paging") diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 65129fa7ec..373712b334 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -209,6 +209,7 @@ fn run() -> Result { } else { let inputs = vec![Input::ordinary_file(OsStr::new("cache"))]; let config = app.config(&inputs)?; + println!("{:#?}", config); run_controller(inputs, &config) } @@ -217,6 +218,8 @@ fn run() -> Result { let inputs = app.inputs()?; let config = app.config(&inputs)?; + println!("{:#?}", config); + if app.matches.is_present("list-languages") { list_languages(&config)?; Ok(true) From fd3f498d38c19f0f4a0460cb00b091dc1e69ba0f Mon Sep 17 00:00:00 2001 From: Alexander Karlis Date: Sat, 12 Sep 2020 00:26:53 -0400 Subject: [PATCH 5/6] removed printlns, updated Changelog, updated man --- CHANGELOG.md | 2 ++ assets/manual/bat.1.in | 6 ++++++ src/bin/bat/app.rs | 1 - src/bin/bat/main.rs | 3 --- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f604c0a847..1080d4aca6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ - Added support for the `NO_COLOR` environment variable, see #1021 and #1031 (@eth-p) - Added `-P` short flag to disable paging, revised man page description, see #1075 and #1082 (@LordFlashmeow) +- Added `--force-colorization` flag & `-f` short flag to provide an alias for forced colorization/decorization, \ +revised man page description, see #1141 (@alexanderkarlis) ## Bugfixes diff --git a/assets/manual/bat.1.in b/assets/manual/bat.1.in index 740d69e4c9..d4951de7ba 100644 --- a/assets/manual/bat.1.in +++ b/assets/manual/bat.1.in @@ -87,6 +87,12 @@ Specify when to use the decorations that have been specified via '\-\-style'. Th automatic mode only enables decorations if an interactive terminal is detected. Possible values: *auto*, never, always. .HP +\fB\-f\fR, \fB\-\-force\-colorization\fR +.IP +Alias for '--decorations=always --color=always'. This is useful \ +if the output of bat is piped to another program, but you want \ +to keep the colorization/decorations. +.HP \fB\-\-paging\fR .IP Specify when to use the pager. To disable the pager, use \&'\-\-paging=never' or its alias, diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 9e4d0f75ad..b1122f0b87 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -288,7 +288,6 @@ impl App { fn style_components(&self) -> Result { let matches = &self.matches; - println!("{:#?}", matches); Ok(StyleComponents( if matches.value_of("decorations") == Some("never") { HashSet::new() diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs index 373712b334..65129fa7ec 100644 --- a/src/bin/bat/main.rs +++ b/src/bin/bat/main.rs @@ -209,7 +209,6 @@ fn run() -> Result { } else { let inputs = vec![Input::ordinary_file(OsStr::new("cache"))]; let config = app.config(&inputs)?; - println!("{:#?}", config); run_controller(inputs, &config) } @@ -218,8 +217,6 @@ fn run() -> Result { let inputs = app.inputs()?; let config = app.config(&inputs)?; - println!("{:#?}", config); - if app.matches.is_present("list-languages") { list_languages(&config)?; Ok(true) From e7f88a54804135af69d2e0c06b7c1578b0d7eab0 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Mon, 14 Sep 2020 10:59:08 +0200 Subject: [PATCH 6/6] Remove unnecessary parenthesis --- src/bin/bat/app.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index b1122f0b87..8249e3c93b 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -177,8 +177,8 @@ impl App { term_width: maybe_term_width.unwrap_or(Term::stdout().size().1 as usize), loop_through: !(self.interactive_output || self.matches.value_of("color") == Some("always") - || (self.matches.value_of("decorations") == Some("always") - || self.matches.is_present("force-colorization"))), + || self.matches.value_of("decorations") == Some("always") + || self.matches.is_present("force-colorization")), tab_width: self .matches .value_of("tabs")