Hello all, attached is a patch for bug #26512 http://savannah.gnu.org/bugs/index.php?26512
Is it correct? make distcheck still passes all tests. There's a seemingly useless C_RESET at every end of line, just before the next color sequence at the start of the next line -- but that's the same behaviour as "ls -x" before the patch, so maybe it is needed? Could you please incorporate this into the next release? The change in behaviour was introduced with the following commit. C_NORM was unused since then. commit 483297d5ddaea930d61da1da9c3f052cbd3c3810 Author: Ed Avis <e...@membled.com> Date: Tue Feb 12 12:22:35 2008 +0100 ls --color no longer outputs unnecessary escape sequences In --color mode, plain files do not get any color, not even white. When no highlighting is required, ls outputs no escape sequence at all. * src/ls.c (print_with_color): (used_color): New global. (indicator_no) [C_RESET]: New enum value. (indicator_name) ["rs"]: Corresponding new string. (color_indicator): Make the 'normal' and 'file' markers be NULL. Use "rs" (C_RESET) to reset to ordinary colors. (process_signals): Restore default colors only if necessary. (main): Don't call prep_non_filename_text here. (print_name_with_quoting): Call it here, instead. > (prep_non_filename_text): Use C_RESET, not C_NORM. (print_color_indicator): Return bool, not void. Print nothing, when possible. (put_indicator): Call prep_non_filename_text the first time. * tests/misc/ls-misc: Test for above. * tests/ls/color-dtype-dir: Adapt: no escapes around regular file name. * TODO: Remove item. * NEWS: Mention this. Moritz
diff --git a/src/ls.c b/src/ls.c index 680679a..4cfb7c7 100644 --- a/src/ls.c +++ b/src/ls.c @@ -1149,6 +1149,17 @@ restore_default_color (void) put_indicator (&color_indicator[C_RIGHT]); } +static void +set_normal_color (void) +{ + if (color_indicator[C_NORM].string != NULL) + { + put_indicator (&color_indicator[C_LEFT]); + put_indicator (&color_indicator[C_NORM]); + put_indicator (&color_indicator[C_RIGHT]); + } +} + /* An ordinary signal was received; arrange for the program to exit. */ static void @@ -3444,6 +3455,8 @@ print_current_files (void) case long_format: for (i = 0; i < cwd_n_used; i++) { + if (print_with_color) + set_normal_color (); print_long_format (sorted_file[i]); DIRED_PUTCHAR ('\n'); } @@ -4048,6 +4061,9 @@ print_file_name_and_frills (const struct fileinfo *f, size_t start_col) { char buf[MAX (LONGEST_HUMAN_READABLE + 1, INT_BUFSIZE_BOUND (uintmax_t))]; + if (print_with_color) + set_normal_color (); + if (print_inode) printf ("%*s ", format == with_commas ? 0 : inode_number_width, format_inode (buf, sizeof buf, f));