From 8b481dd41f50e889031ed198dd66a95f32d6fb5b Mon Sep 17 00:00:00 2001 From: Ethan P Date: Wed, 27 May 2020 16:38:43 -0700 Subject: [PATCH] Add support for NO_COLOR env var (#1021) --- CHANGELOG.md | 3 +++ src/bin/bat/app.rs | 2 +- src/bin/bat/clap_app.rs | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 149901b8..410605a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # unreleased ## Features + +- Added support for the `NO_COLOR` environment variable, see #1021 and #1031 (@eth-p) + ## Bugfixes ## Other ## New syntaxes diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 4aa742a0..b924ab29 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -165,7 +165,7 @@ impl App { colored_output: match self.matches.value_of("color") { Some("always") => true, Some("never") => false, - Some("auto") | _ => self.interactive_output, + Some("auto") | _ => env::var_os("NO_COLOR").is_none() && self.interactive_output, }, paging_mode, term_width: maybe_term_width.unwrap_or(Term::stdout().size().1 as usize), diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index 9441182b..4182b76e 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -1,8 +1,9 @@ use clap::{crate_name, crate_version, App as ClapApp, AppSettings, Arg, ArgGroup, SubCommand}; +use std::env; use std::path::Path; pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> { - let clap_color_setting = if interactive_output { + let clap_color_setting = if interactive_output && env::var_os("NO_COLOR").is_none() { AppSettings::ColoredHelp } else { AppSettings::ColorNever