From 26aa1f346e3fe1d366496007dc935abd4d661462 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Sat, 19 Dec 2020 17:08:37 -0800 Subject: [PATCH] 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. --- src/uu/ls/src/ls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 6c4ba38b1..9ce7ee818 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -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),