summaryrefslogtreecommitdiff
path: root/src/dircolors.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2008-12-31 19:17:31 +0100
committerJim Meyering <meyering@redhat.com>2009-02-10 14:47:39 +0100
commitadc62b5d9f3b4ab575c57b1b76eb6ad257a09f2c (patch)
tree34cceba4a76f87a598656faf326c95f5ef945fe0 /src/dircolors.c
parent1f4fcd083d3c24349a4cc7b4a4d0ef4aad9d26e6 (diff)
downloadcoreutils-adc62b5d9f3b4ab575c57b1b76eb6ad257a09f2c.tar.xz
ls: clean up after wrapped+colored file names with clear-to-EOL
This change addresses a relatively unusual case: ls --color, with a highlighted name being printed initially in the last row of a terminal emulator (possibly followed by other lines of output) such that it is wrapped onto the following line, as the terminal emulator scrolls the output. That would cause the entire following line to be highlighted, even if the name happened to use only one position. The least-invasive patch would have made colorized output larger for all uses. The approach taken below is more invasive, but limits the increase in overhead to only those lines that are expected to wrap. * src/ls.c (enum indicator_no): Add C_CLR_TO_EOL. (indicator_name): Add "cl". (color_indicator): Add default escape codes for "cl". (print_long_format): Propagate width to print_name_with_quoting. (print_name_with_quoting): Print new C_CLR_TO_EOL string if needed. Return the width of what we're printing. (print_file_name_and_frills): Propagate width. (print_type_indicator): Return bool (aka width). (print_many_per_line): Pass column position to print_* function. (print_current_files): Likewise. (print_horizontal): Likewise. (print_with_commas): Likewise. * src/dircolors.c (slack_codes): Add "CLRTOEOL". (ls_codes): Add "cl". * tests/ls/color-clear-to-eol: New file. Test for this fix. * tests/Makefile.am (TESTS): Add ls/color-clear-to-eol. * THANKS: Update. Reported by Alexander V. Lukyanov. See thread for details: http://thread.gmane.org/gmane.linux.kernel/740021/focus=14824 Thanks to Jan Engelhardt for helping me reproduce the problem. Demonstrate with this in an 80-column xterm: seq 200 # to start in the "bottom" row touch zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz.foo env LS_COLORS='*.foo=0;31;42' ls -og --color=always Before the fix, you'd see something like this: (where the file name is printed in red on a green background, and each "=" denotes a space on a green background) ... -rw-r--r-- 1 0 Feb 5 11:31 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\ zzzzzzzzzzzzzz.foo=================================================== After the patch, the trailing green spaces are gone: -rw-r--r-- 1 0 Feb 5 11:31 zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\ zzzzzzzzzzzzzz.foo
Diffstat (limited to 'src/dircolors.c')
-rw-r--r--src/dircolors.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/dircolors.c b/src/dircolors.c
index 0980e3df1..7dad7fd9b 100644
--- a/src/dircolors.c
+++ b/src/dircolors.c
@@ -64,14 +64,14 @@ static const char *const slack_codes[] =
"CHR", "CHAR", "DOOR", "EXEC", "LEFT", "LEFTCODE", "RIGHT", "RIGHTCODE",
"END", "ENDCODE", "SUID", "SETUID", "SGID", "SETGID", "STICKY",
"OTHER_WRITABLE", "OWR", "STICKY_OTHER_WRITABLE", "OWT", "CAPABILITY",
- "HARDLINK", NULL
+ "HARDLINK", "CLRTOEOL", NULL
};
static const char *const ls_codes[] =
{
"no", "no", "fi", "rs", "di", "ln", "ln", "ln", "or", "mi", "pi", "pi",
"so", "bd", "bd", "cd", "cd", "do", "ex", "lc", "lc", "rc", "rc", "ec", "ec",
- "su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", "hl", NULL
+ "su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", "hl", "cl", NULL
};
#define array_len(Array) (sizeof (Array) / sizeof *(Array))
verify (array_len (slack_codes) == array_len (ls_codes));