From: Lennart Poettering Date: Wed, 6 May 2020 12:46:37 +0000 (+0200) Subject: format-table: display an empty strv cell the same way as an empty cell X-Git-Tag: v246-rc1~429^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=557b0841b7b4d03c85f3e627dd9f20d977974605;p=thirdparty%2Fsystemd.git format-table: display an empty strv cell the same way as an empty cell An empty list conceptually is very close to null, hence let's show it the same way, i.e. using the defined "empty" string, and greyed out. --- diff --git a/src/shared/format-table.c b/src/shared/format-table.c index aac8ac47faf..cef96343abd 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -1272,6 +1272,9 @@ static const char *table_data_format(Table *t, TableData *d, bool avoid_uppercas case TABLE_STRV: { char *p; + if (strv_isempty(d->strv)) + return strempty(t->empty_string); + p = strv_join(d->strv, "\n"); if (!p) return NULL; @@ -1694,6 +1697,20 @@ static char *align_string_mem(const char *str, const char *url, size_t new_lengt return ret; } +static bool table_data_isempty(TableData *d) { + assert(d); + + if (d->type == TABLE_EMPTY) + return true; + + /* Let's also consider an empty strv as truly empty. */ + if (d->type == TABLE_STRV) + return strv_isempty(d->strv); + + /* Note that an empty string we do not consider empty here! */ + return false; +} + static const char* table_data_color(TableData *d) { assert(d); @@ -1701,7 +1718,7 @@ static const char* table_data_color(TableData *d) { 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) + if (table_data_isempty(d)) return ansi_grey(); return NULL;