1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57:44 +00:00

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 2020-12-19 17:08:37 -08:00 committed by Sylvestre Ledru
parent 158754f4ab
commit 26aa1f346e

View file

@ -622,7 +622,7 @@ fn display_file_name(
let mut width = UnicodeWidthStr::width(&*name); let mut width = UnicodeWidthStr::width(&*name);
let color = match options.opt_str("color") { let color = match options.opt_str("color") {
None => true, None => stdout_isatty(),
Some(val) => match val.as_ref() { Some(val) => match val.as_ref() {
"always" | "yes" | "force" => true, "always" | "yes" | "force" => true,
"auto" | "tty" | "if-tty" => atty::is(atty::Stream::Stdout), "auto" | "tty" | "if-tty" => atty::is(atty::Stream::Stdout),