shared/format-table: add helper to sync widths of a table array

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-13 13:23:04 +02:00
parent d66923ea07
commit 4d620b49f5
2 changed files with 24 additions and 0 deletions
+23
View File
@@ -2250,6 +2250,29 @@ int _table_sync_column_widths(size_t column, Table *a, ...) {
return r;
}
int table_sync_all_column_widths(size_t column, Table **a) {
size_t max = 0;
int r;
/* Make the specified column have the same width in the tables. */
for (Table **t = a; t && *t; t++) {
size_t w;
r = table_data_requested_width(*t, column, &w);
if (r < 0)
return log_error_errno(r, "Failed to query table column width: %m");
max = MAX(max, w);
}
r = 0;
for (Table **t = a; t && *t; t++)
RET_GATHER(r, table_set_column_width(*t, column, max));
return r;
}
int table_print_full(Table *t, FILE *f, bool flush) {
_cleanup_free_ size_t *sorted = NULL;
int r;
+1
View File
@@ -149,6 +149,7 @@ int table_data_requested_width(Table *table, size_t column, size_t *ret);
int table_set_column_width(Table *t, size_t column, size_t width);
int _table_sync_column_widths(size_t column, Table *a, ...);
#define table_sync_column_widths(column, a, ...) _table_sync_column_widths(column, a, __VA_ARGS__, NULL)
int table_sync_all_column_widths(size_t column, Table **a);
int table_print_full(Table *t, FILE *f, bool flush);
static inline int table_print(Table *t) {