From: Lennart Poettering Date: Mon, 29 Jul 2019 16:39:05 +0000 (+0200) Subject: format-table: automatically show empty cells in grey X-Git-Tag: v243-rc1~9^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2cb86a3e16064517340b1e3a923d18b764bb00e2;p=thirdparty%2Fsystemd.git format-table: automatically show empty cells in grey --- diff --git a/src/shared/format-table.c b/src/shared/format-table.c index 39fc80571ea..54e8f68ab0b 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -1341,6 +1341,19 @@ static char *align_string_mem(const char *str, const char *url, size_t new_lengt return ret; } +static const char* table_data_color(TableData *d) { + assert(d); + + if (d->color) + return d->color; + + /* Let's implicitly color all "empty" cells in grey, in case an "empty_string" is set that is not empty */ + if (d->type == TABLE_EMPTY) + return ansi_grey(); + + return NULL; +} + int table_print(Table *t, FILE *f) { size_t n_rows, *minimum_width, *maximum_width, display_columns, *requested_width, i, j, table_minimum_width, table_maximum_width, table_requested_width, table_effective_width, @@ -1614,16 +1627,16 @@ int table_print(Table *t, FILE *f) { if (j > 0) fputc(' ', f); /* column separator */ - if (d->color && colors_enabled()) { + if (table_data_color(d) && colors_enabled()) { if (row == t->data) /* first undo header underliner */ fputs(ANSI_NORMAL, f); - fputs(d->color, f); + fputs(table_data_color(d), f); } fputs(field, f); - if (colors_enabled() && (d->color || row == t->data)) + if (colors_enabled() && (table_data_color(d) || row == t->data)) fputs(ANSI_NORMAL, f); }