]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Two problems fixed by these changes from Joakim Rosqvist.
authorJim Meyering <jim@meyering.net>
Sun, 29 Dec 1996 03:47:34 +0000 (03:47 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 29 Dec 1996 03:47:34 +0000 (03:47 +0000)
Quoting Joakim:
1) The "total" number and the size of the first file as
output from 'ls --color -s' did not get colorized according
to the "no"-argument in LS_COLORS. Fixed by adding a function
prep_non_filename_text which prints the C_LEFT C_NORM C_RIGHT
strings (or C_END). It is called from main before any text is
output, and from print_name_with_quoting after having output a
colorized filename.
2) If the "no"-argument of LS_COLORS is set, the terminal will be
set to print in that color after ls exits. The man-pages suggests
setting "no" and "fi" to the terminals default colors to avoid
the problem, but that would mean I can't use anything but the
default color for regular files and non-filename text. Fixed by
outputting C_LEFT immediately followed by C_RIGHT right before
exit, which restores the default color.

src/ls.c

index 1054dd27f7eb5231ea63769d2a29c02e0363bf6f..590a4b6371dea083e16a99b30d655a2e52ebbf86 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -194,6 +194,7 @@ static void print_long_format __P ((const struct fileinfo *f));
 static void print_many_per_line __P ((void));
 static void print_name_with_quoting __P ((const char *p, unsigned int mode,
                                          int linkok));
+static void prep_non_filename_text __P ((void));
 static void print_type_indicator __P ((unsigned int mode));
 static void print_with_commas __P ((void));
 static void queue_directory __P ((const char *name, const char *realname));
@@ -673,7 +674,10 @@ main (int argc, char **argv)
     usage (EXIT_SUCCESS);
 
   if (print_with_color)
-    parse_ls_color ();
+    {
+      parse_ls_color ();
+      prep_non_filename_text ();
+    }
 
   format_needs_stat = sort_type == sort_time || sort_type == sort_size
     || format == long_format
@@ -743,6 +747,13 @@ main (int argc, char **argv)
   if (fclose (stdout) == EOF)
     error (EXIT_FAILURE, errno, _("write error"));
 
+  /* Restore default color before exiting */
+  if (print_with_color)
+    {
+      put_indicator (&color_indicator[C_LEFT]);
+      put_indicator (&color_indicator[C_RIGHT]);
+    }
+
   exit (exit_status);
 }
 
@@ -1285,7 +1296,7 @@ get_funky_string (char **dest, const char **src, int equals_end)
              *(q++) = *(p++) & 037;
              ++count;
            }
-         else if ( *p == '?' )
+         else if ( *p == '?')
            {
              *(q++) = 127;
              ++count;
@@ -2137,7 +2148,7 @@ print_long_format (const struct fileinfo *f)
       if (f->linkname)
        {
          FPUTS_LITERAL (" -> ", stdout);
-         print_name_with_quoting (f->linkname, f->linkmode, f->linkok-1);
+         print_name_with_quoting (f->linkname, f->linkmode, f->linkok - 1);
          if (indicator_style != none)
            print_type_indicator (f->linkmode);
        }
@@ -2300,15 +2311,19 @@ print_name_with_quoting (const char *p, unsigned int mode, int linkok)
     free (quoted);
 
   if (print_with_color)
+    prep_non_filename_text ();
+}
+
+static void
+prep_non_filename_text (void)
+{
+  if (color_indicator[C_END].string != NULL)
+    put_indicator (&color_indicator[C_END]);
+  else
     {
-      if (color_indicator[C_END].string != NULL)
-       put_indicator (&color_indicator[C_END]);
-      else
-       {
-         put_indicator (&color_indicator[C_LEFT]);
-         put_indicator (&color_indicator[C_NORM]);
-         put_indicator (&color_indicator[C_RIGHT]);
-       }
+      put_indicator (&color_indicator[C_LEFT]);
+      put_indicator (&color_indicator[C_NORM]);
+      put_indicator (&color_indicator[C_RIGHT]);
     }
 }