From 4b61beaa7591c922d2f7da55853e7b0abab009e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20Ker=C3=A4nen?= Date: Sun, 1 Oct 2017 00:02:57 +0300 Subject: [PATCH] Add flag to force color Color can now be forced on even when piping the output. Changed the --no-color flag to --color which uses the same options that ripgrep uses for --color (excluding ansi). Closes #49. --- src/main.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7d0b044..cac48aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -389,10 +389,12 @@ fn main() { .long("absolute-path") .short("a") .help("Show absolute instead of relative paths")) - .arg(Arg::with_name("no-color") - .long("no-color") - .short("n") - .help("Do not colorize output")) + .arg(Arg::with_name("color") + .long("color") + .short("c") + .takes_value(true) + .possible_values(&["never", "auto", "always"]) + .help("When to use color in the output. The default is auto.")) .arg(Arg::with_name("depth") .long("max-depth") .short("d") @@ -461,8 +463,11 @@ fn main() { let case_sensitive = matches.is_present("case-sensitive") || pattern.chars().any(char::is_uppercase); - let colored_output = !matches.is_present("no-color") && - atty::is(Stream::Stdout); + let colored_output = match matches.value_of("color") { + Some("always") => true, + Some("never") => false, + _ => atty::is(Stream::Stdout) + }; let ls_colors = if colored_output {