]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
format-table: allow forcing arbitrary width tables
authorLennart Poettering <lennart@poettering.net>
Thu, 9 Jan 2020 17:24:00 +0000 (18:24 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 10 Jan 2020 02:53:28 +0000 (11:53 +0900)
Useful for implementing systemctl's --full.

See #14470

src/shared/format-table.c

index 47d56dd085baf3676025c3c3cce28f4f7c431684..62ba0c5df3b729efe407ee2840e08679eb680011 100644 (file)
@@ -117,7 +117,8 @@ struct Table {
         size_t n_cells;
 
         bool header;   /* Whether to show the header row? */
-        size_t width;  /* If != (size_t) -1 the width to format this table in */
+        size_t width;  /* If == 0 format this as wide as necessary. If (size_t) -1 format this to console
+                        * width or less wide, but not wider. Otherwise the width to format this table in. */
 
         TableData **data;
         size_t n_allocated;
@@ -1619,9 +1620,9 @@ int table_print(Table *t, FILE *f) {
         }
 
         /* Calculate effective table width */
-        if (t->width != (size_t) -1)
+        if (t->width != 0 && t->width != (size_t) -1)
                 table_effective_width = t->width;
-        else if (pager_have() || !isatty(STDOUT_FILENO))
+        else if (t->width == 0 || pager_have() || !isatty(STDOUT_FILENO))
                 table_effective_width = table_requested_width;
         else
                 table_effective_width = MIN(table_requested_width, columns());