From f5268e2749d5649a3364550ef54bf31d9aa9c4e1 Mon Sep 17 00:00:00 2001 From: Moritz Orbach Date: Tue, 16 Feb 2010 22:48:00 +0000 Subject: ls: fix a regression by honoring NORMAL attributes again Output the NORMAL attribute before non file name text. This attribute will continue into file names that would not otherwise be colored unless FILE is also set. The regression was introduced with commit 483297d5, 28-02-2009, "ls --color no longer outputs unnecessary escape sequences". * src/ls.c (set_normal_color): A new function to output the NORMAL attribute sequence if it's enabled. (print_current_files): Output NORMAL before printing long format info. (print_file_name_and_frills): Output NORMAL before printing file name. (print_color_indicator): Reset the attributes before a file name with attributes so that NORMAL attributes will not combine with them. (print_name_with_quoting): Ensure attributes are reset after printing the file name if NORMAL attributes were output. * tests/ls/color-norm: A new test for NORMAL and FILE combinations. * tests/Makefile.am: Reference the new test. * NEWS: Mention the fix. Reported in https://savannah.gnu.org/bugs/?26512 --- src/ls.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ls.c b/src/ls.c index 680679a9a..3025a76ef 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 (print_with_color && is_colored (C_NORM)) + { + 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,7 @@ print_current_files (void) case long_format: for (i = 0; i < cwd_n_used; i++) { + set_normal_color (); print_long_format (sorted_file[i]); DIRED_PUTCHAR ('\n'); } @@ -4004,7 +4016,9 @@ print_name_with_quoting (const struct fileinfo *f, const char* name = symlink_target ? f->linkname : f->name; bool used_color_this_time - = (print_with_color && print_color_indicator (f, symlink_target)); + = (print_with_color + && (print_color_indicator (f, symlink_target) + || is_colored (C_NORM))); if (stack) PUSH_CURRENT_DIRED_POS (stack); @@ -4048,6 +4062,8 @@ 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))]; + set_normal_color (); + if (print_inode) printf ("%*s ", format == with_commas ? 0 : inode_number_width, format_inode (buf, sizeof buf, f)); @@ -4218,6 +4234,9 @@ print_color_indicator (const struct fileinfo *f, bool symlink_target) = ext ? &(ext->seq) : &color_indicator[type]; if (s->string != NULL) { + /* Need to reset so not dealing with attribute combinations */ + if (is_colored (C_NORM)) + restore_default_color (); put_indicator (&color_indicator[C_LEFT]); put_indicator (s); put_indicator (&color_indicator[C_RIGHT]); -- cgit v1.2.3-70-g09d2