From 5d43617e8ad863ed041309edefd018fdcaa87038 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 30 Jan 2010 16:52:46 -0600 Subject: ls --color: don't emit a final no-op escape sequence * src/ls.c (main): With --color, avoid emitting the final color- resetting escape sequence when it would be a no-op. * tests/ls/color-clear-to-eol: Adjust expected output accordingly. * tests/ls/color-dtype-dir: Likewise. * tests/ls/multihardlink: Likewise. * tests/ls/stat-free-symlinks: Likewise. * tests/misc/ls-misc: Likewise. * NEWS (Changes in behavior): Mention it. C de-Avillez rebased and adapted four of the new sl-dangle* tests in tests/misc/ls-misc. Reported by Jim Avera in http://bugs.launchpad.net/ubuntu/+source/coreutils/+bug/494663 --- src/ls.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/ls.c') diff --git a/src/ls.c b/src/ls.c index 9ef7eba21..680679a9a 100644 --- a/src/ls.c +++ b/src/ls.c @@ -1442,7 +1442,15 @@ main (int argc, char **argv) int j; if (used_color) - restore_default_color (); + { + /* Skip the restore when it would be a no-op, i.e., + when left is "\033[" and right is "m". */ + if (!(color_indicator[C_LEFT].len == 2 + && memcmp (color_indicator[C_LEFT].string, "\033[", 2) == 0 + && color_indicator[C_RIGHT].len == 1 + && color_indicator[C_RIGHT].string[0] == 'm')) + restore_default_color (); + } fflush (stdout); /* Restore the default signal handling. */ -- cgit v1.2.3-54-g00ecf