Skip to content

Commit c12249b

Browse files
committed
fix: display color when NO_COLOR is an empty string
1 parent 51203ff commit c12249b

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## Bugfixes
66

7+
- Fix `NO_COLOR` support, see #2767 (@acuteenvy)
8+
79
## Other
810

911
- Upgrade to Rust 2021 edition #2748 (@cyqsimon)

src/bin/bat/app.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ fn is_truecolor_terminal() -> bool {
2929
.unwrap_or(false)
3030
}
3131

32+
pub fn env_no_color() -> bool {
33+
env::var_os("NO_COLOR").is_some_and(|x| !x.is_empty())
34+
}
35+
3236
pub struct App {
3337
pub matches: ArgMatches,
3438
interactive_output: bool,
@@ -207,7 +211,7 @@ impl App {
207211
|| match self.matches.get_one::<String>("color").map(|s| s.as_str()) {
208212
Some("always") => true,
209213
Some("never") => false,
210-
Some("auto") => env::var_os("NO_COLOR").is_none() && self.interactive_output,
214+
Some("auto") => !env_no_color() && self.interactive_output,
211215
_ => unreachable!("other values for --color are not allowed"),
212216
},
213217
paging_mode,

src/bin/bat/clap_app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static VERSION: Lazy<String> = Lazy::new(|| {
1919
});
2020

2121
pub fn build_app(interactive_output: bool) -> Command {
22-
let color_when = if interactive_output && env::var_os("NO_COLOR").is_none() {
22+
let color_when = if interactive_output && !crate::app::env_no_color() {
2323
ColorChoice::Auto
2424
} else {
2525
ColorChoice::Never

0 commit comments

Comments
 (0)