format-table: allow forcing arbitrary width tables

Useful for implementing systemctl's --full.

See #14470
This commit is contained in:
Lennart Poettering 2020-01-09 18:24:00 +01:00 committed by Yu Watanabe
parent 79bb680cbf
commit bcf00b6c0a
1 changed files with 4 additions and 3 deletions

View 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());