Skip to content

Commit

Permalink
Add support for NO_COLOR env var (sharkdp#1021)
Browse files Browse the repository at this point in the history
  • Loading branch information
eth-p committed May 27, 2020
1 parent 6f88ba0 commit 96b92a8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/bin/bat/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion src/bin/bat/clap_app.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 96b92a8

Please sign in to comment.