on master help sign in
Add support for NO_COLOR env var (#1021)
8b481ddEthan P
CHANGELOG.md+3
@@ -1,6 +1,9 @@
1# unreleased
1# unreleased
2
2
3## Features
3## Features
4+
5+- Added support for the `NO_COLOR` environment variable, see #1021 and #1031 (@eth-p)
6+
4## Bugfixes
7## Bugfixes
5## Other
8## Other
6## New syntaxes
9## New syntaxes
src/bin/bat/app.rs+1−1
@@ -165,7 +165,7 @@ impl App {
165 colored_output: match self.matches.value_of("color") {
165 colored_output: match self.matches.value_of("color") {
166 Some("always") => true,
166 Some("always") => true,
167 Some("never") => false,
167 Some("never") => false,
168− Some("auto") | _ => self.interactive_output,
168+ Some("auto") | _ => env::var_os("NO_COLOR").is_none() && self.interactive_output,
169 },
169 },
170 paging_mode,
170 paging_mode,
171 term_width: maybe_term_width.unwrap_or(Term::stdout().size().1 as usize),
171 term_width: maybe_term_width.unwrap_or(Term::stdout().size().1 as usize),
src/bin/bat/clap_app.rs+2−1
@@ -1,8 +1,9 @@
1use clap::{crate_name, crate_version, App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand};
1use clap::{crate_name, crate_version, App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand};
2+use std::env;
2use std::path::Path;
3use std::path::Path;
3
4
4pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
5pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
5− let clap_color_setting = if interactive_output {
6+ let clap_color_setting = if interactive_output && env::var_os("NO_COLOR").is_none() {
6 AppSettings::ColoredHelp
7 AppSettings::ColoredHelp
7 } else {
8 } else {
8 AppSettings::ColorNever
9 AppSettings::ColorNever