]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
format-table: before outputting a color, check if colors are available
authorLennart Poettering <lennart@poettering.net>
Tue, 6 Nov 2018 17:37:21 +0000 (18:37 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 30 Nov 2018 15:46:10 +0000 (16:46 +0100)
This is in many cases redundant, as a similar check is done by various
callers already, but in other cases (where we read the color from a
static table for example), it's nice to let the color check be done by
the table code itself, and since it doesn't hurt in the other cases just
do it again.

src/shared/format-table.c

index a99f1cff3c5dd7c8c40b17cf85068330c5084819..959bfc53c4f1d441bd64ed22c4112f72c500125a 100644 (file)
@@ -1209,13 +1209,13 @@ int table_print(Table *t, FILE *f) {
                         if (j > 0)
                                 fputc(' ', f); /* column separator */
 
-                        if (d->color)
+                        if (d->color && colors_enabled())
                                 fputs(d->color, f);
 
                         fputs(field, f);
 
-                        if (d->color)
-                                fputs(ansi_normal(), f);
+                        if (d->color && colors_enabled())
+                                fputs(ANSI_NORMAL, f);
                 }
 
                 fputc('\n', f);