on master help sign in
Add support for NO_COLOR env var (#1021)
commit8b481dd41f50e889031ed198dd66a95f32d6fb5b authorEthan P <eth-p+git@hidden.email> dateWed 27 May 2020, 16:38 (6 years ago) parent6f88ba0
3 files changed+6−2
CHANGELOG.md+3 src/bin/bat/app.rs+1−1 src/bin/bat/clap_app.rs+2−1
CHANGELOG.md+3
@@ -1,6 +1,9 @@
11# unreleased
22
33## Features
4+
5+- Added support for the `NO_COLOR` environment variable, see #1021 and #1031 (@eth-p)
6+
47## Bugfixes
58## Other
69## New syntaxes
src/bin/bat/app.rs+1−1
@@ -165,7 +165,7 @@ impl App {
165165 colored_output: match self.matches.value_of("color") {
166166 Some("always") => true,
167167 Some("never") => false,
168− Some("auto") | _ => self.interactive_output,
168+ Some("auto") | _ => env::var_os("NO_COLOR").is_none() && self.interactive_output,
169169 },
170170 paging_mode,
171171 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 @@
11use clap::{crate_name, crate_version, App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand};
2+use std::env;
23use std::path::Path;
34
45pub 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() {
67 AppSettings::ColoredHelp
78 } else {
89 AppSettings::ColorNever