mirror of
https://github.com/sharkdp/bat.git
synced 2024-11-28 18:53:34 +01:00
fix: display color when NO_COLOR is an empty string (#2767)
This commit is contained in:
parent
748e2a681f
commit
28990bc451
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
## Bugfixes
|
## Bugfixes
|
||||||
|
|
||||||
|
- Fix `NO_COLOR` support, see #2767 (@acuteenvy)
|
||||||
|
|
||||||
## Other
|
## Other
|
||||||
|
|
||||||
- Upgrade to Rust 2021 edition #2748 (@cyqsimon)
|
- Upgrade to Rust 2021 edition #2748 (@cyqsimon)
|
||||||
|
@ -29,6 +29,10 @@ fn is_truecolor_terminal() -> bool {
|
|||||||
.unwrap_or(false)
|
.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 struct App {
|
||||||
pub matches: ArgMatches,
|
pub matches: ArgMatches,
|
||||||
interactive_output: bool,
|
interactive_output: bool,
|
||||||
@ -207,7 +211,7 @@ impl App {
|
|||||||
|| match self.matches.get_one::<String>("color").map(|s| s.as_str()) {
|
|| match self.matches.get_one::<String>("color").map(|s| s.as_str()) {
|
||||||
Some("always") => true,
|
Some("always") => true,
|
||||||
Some("never") => false,
|
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"),
|
_ => unreachable!("other values for --color are not allowed"),
|
||||||
},
|
},
|
||||||
paging_mode,
|
paging_mode,
|
||||||
|
@ -19,7 +19,7 @@ static VERSION: Lazy<String> = Lazy::new(|| {
|
|||||||
});
|
});
|
||||||
|
|
||||||
pub fn build_app(interactive_output: bool) -> Command {
|
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
|
ColorChoice::Auto
|
||||||
} else {
|
} else {
|
||||||
ColorChoice::Never
|
ColorChoice::Never
|
||||||
|
Loading…
Reference in New Issue
Block a user