ls: only print colors if stdout is a tty

Previously if no --color argument was input, we would always print
colors in the output. This breaks `configure` scripts which run `ls`
and then compare the output against what they expect to see, since the
left side has ANSI escape sequences and the right side doesn't.

Instead, only print escape sequences if a TTY is present, or if
`--color=always` is specified.

Fixes #1638.
This commit is contained in:
Kevin Burke
2021-02-12 11:37:32 +01:00
committed by Sylvestre Ledru
parent 158754f4ab
commit 26aa1f346e
+1 -1
View File
@@ -622,7 +622,7 @@ fn display_file_name(
let mut width = UnicodeWidthStr::width(&*name);
let color = match options.opt_str("color") {
None => true,
None => stdout_isatty(),
Some(val) => match val.as_ref() {
"always" | "yes" | "force" => true,
"auto" | "tty" | "if-tty" => atty::is(atty::Stream::Stdout),