summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLena <126529524+acuteenvy@users.noreply.github.com>2023-12-02 12:43:55 +0100
committerGitHub <noreply@github.com>2023-12-02 11:43:55 +0000
commit28990bc4512770a2669de33cf71a2edb26abd061 (patch)
tree39ce3934938cbb6413cd2cf5c9cfe0f0dcd89f76
parent748e2a681ff622dbc075dbeb3e36126ebf3fa3a4 (diff)
fix: display color when NO_COLOR is an empty string (#2767)
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/bin/bat/app.rs6
-rw-r--r--src/bin/bat/clap_app.rs2
3 files changed, 8 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6ebf17ae..838bcf23 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@
## Bugfixes
+- Fix `NO_COLOR` support, see #2767 (@acuteenvy)
+
## Other
- Upgrade to Rust 2021 edition #2748 (@cyqsimon)
diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs
index bb67fc3a..09430623 100644
--- a/src/bin/bat/app.rs
+++ b/src/bin/bat/app.rs
@@ -29,6 +29,10 @@ fn is_truecolor_terminal() -> bool {
.unwrap_or(false)
}
+pub fn env_no_color() -> bool {
+ env::var_os("NO_COLOR").is_some_and(|x| !x.is_empty())
+}
+
pub struct App {
pub matches: ArgMatches,
interactive_output: bool,
@@ -207,7 +211,7 @@ impl App {
|| match self.matches.get_one::<String>("color").map(|s| s.as_str()) {
Some("always") => true,
Some("never") => false,
- Some("auto") => env::var_os("NO_COLOR").is_none() && self.interactive_output,
+ Some("auto") => !env_no_color() && self.interactive_output,
_ => unreachable!("other values for --color are not allowed"),
},
paging_mode,
diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs
index 8ffeb5b2..e8222a1d 100644
--- a/src/bin/bat/clap_app.rs
+++ b/src/bin/bat/clap_app.rs
@@ -19,7 +19,7 @@ static VERSION: Lazy<String> = Lazy::new(|| {
});
pub fn build_app(interactive_output: bool) -> Command {
- let color_when = if interactive_output && env::var_os("NO_COLOR").is_none() {
+ let color_when = if interactive_output && !crate::app::env_no_color() {
ColorChoice::Auto
} else {
ColorChoice::Never