summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-12-29 03:47:34 +0000
committerJim Meyering <jim@meyering.net>1996-12-29 03:47:34 +0000
commit5ae342e1a9b8b62b2ce835170ad99afd0d3bae9e (patch)
tree9cb7b11b17c53aac9beab71d6d1d30ef0974646b /src
parent6c635d1f277cd3a7180391e54100d4dfe1fb0a81 (diff)
downloadcoreutils-5ae342e1a9b8b62b2ce835170ad99afd0d3bae9e.tar.xz
Two problems fixed by these changes from Joakim Rosqvist.
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.
Diffstat (limited to 'src')
-rw-r--r--src/ls.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/ls.c b/src/ls.c
index 1054dd27f..590a4b637 100644
--- 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]);
}
}