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.
This commit is contained in:
Antti Keränen 2017-10-01 00:02:57 +03:00 committed by David Peter
parent 2256affd8f
commit 4b61beaa75

View file

@ -389,10 +389,12 @@ fn main() {
.long("absolute-path") .long("absolute-path")
.short("a") .short("a")
.help("Show absolute instead of relative paths")) .help("Show absolute instead of relative paths"))
.arg(Arg::with_name("no-color") .arg(Arg::with_name("color")
.long("no-color") .long("color")
.short("n") .short("c")
.help("Do not colorize output")) .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") .arg(Arg::with_name("depth")
.long("max-depth") .long("max-depth")
.short("d") .short("d")
@ -461,8 +463,11 @@ fn main() {
let case_sensitive = matches.is_present("case-sensitive") || let case_sensitive = matches.is_present("case-sensitive") ||
pattern.chars().any(char::is_uppercase); pattern.chars().any(char::is_uppercase);
let colored_output = !matches.is_present("no-color") && let colored_output = match matches.value_of("color") {
atty::is(Stream::Stdout); Some("always") => true,
Some("never") => false,
_ => atty::is(Stream::Stdout)
};
let ls_colors = let ls_colors =
if colored_output { if colored_output {