]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
format-table: display an empty strv cell the same way as an empty cell
authorLennart Poettering <lennart@poettering.net>
Wed, 6 May 2020 12:46:37 +0000 (14:46 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 6 May 2020 13:40:15 +0000 (15:40 +0200)
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.

src/shared/format-table.c

index aac8ac47faf899ea62b274762f42ead0a5f04967..cef96343abd98e5fea857789e0050128b3408fab 100644 (file)
@@ -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;