summaryrefslogtreecommitdiff
path: root/src/ls.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2010-01-30 16:52:46 -0600
committerJim Meyering <meyering@redhat.com>2010-02-01 08:26:12 +0100
commit5d43617e8ad863ed041309edefd018fdcaa87038 (patch)
tree97b006c897443e5ff9dd599f95ae3d603c2fd342 /src/ls.c
parent5d4952059fa0d68cfc09ca5f72e6b0124633c79b (diff)
downloadcoreutils-5d43617e8ad863ed041309edefd018fdcaa87038.tar.xz
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
Diffstat (limited to 'src/ls.c')
-rw-r--r--src/ls.c10
1 files changed, 9 insertions, 1 deletions
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. */