From 4d620b49f50065f5c1e32f3ad20ad6069db3bb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 31 Jul 2026 18:27:47 -0600 Subject: [PATCH] shared/format-table: add helper to sync widths of a table array --- src/shared/format-table.c | 23 +++++++++++++++++++++++ src/shared/format-table.h | 1 + 2 files changed, 24 insertions(+) diff --git a/src/shared/format-table.c b/src/shared/format-table.c index 772d3475c1..b0c15ca806 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -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; diff --git a/src/shared/format-table.h b/src/shared/format-table.h index 8c0acac217..8087abfb9e 100644 --- a/src/shared/format-table.h +++ b/src/shared/format-table.h @@ -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) {