From 9c7a5ff6ccfd65cdbfa40d1565c4cf862a49e12f Mon Sep 17 00:00:00 2001 From: David Tardon Date: Fri, 11 Nov 2022 09:12:06 +0100 Subject: [PATCH 1/7] analyze-calendar: avoid unnecessary abbreviation --- src/analyze/analyze-calendar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/analyze/analyze-calendar.c b/src/analyze/analyze-calendar.c index 952fe95c2c..a53d11580b 100644 --- a/src/analyze/analyze-calendar.c +++ b/src/analyze/analyze-calendar.c @@ -91,7 +91,7 @@ static int test_calendar_one(usec_t n, const char *p) { else k = 0; - r = table_add_cell_stringf(table, NULL, "Iter. #%u:", i+1); + r = table_add_cell_stringf(table, NULL, "Iteration #%u:", i+1); if (r < 0) return table_log_add_error(r); From f607ebcac26bfd9f55622b1719c2121849a4c67a Mon Sep 17 00:00:00 2001 From: David Tardon Date: Fri, 11 Nov 2022 09:11:30 +0100 Subject: [PATCH 2/7] analyze-calendar: port to vertical table --- src/analyze/analyze-calendar.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/analyze/analyze-calendar.c b/src/analyze/analyze-calendar.c index a53d11580b..6daab08443 100644 --- a/src/analyze/analyze-calendar.c +++ b/src/analyze/analyze-calendar.c @@ -24,21 +24,15 @@ static int test_calendar_one(usec_t n, const char *p) { if (r < 0) return log_error_errno(r, "Failed to format calendar specification '%s': %m", p); - table = table_new("name", "value"); + table = table_new_vertical(); if (!table) return log_oom(); - table_set_header(table, false); - assert_se(cell = table_get_cell(table, 0, 0)); r = table_set_ellipsize_percent(table, cell, 100); if (r < 0) return r; - r = table_set_align_percent(table, cell, 100); - if (r < 0) - return r; - assert_se(cell = table_get_cell(table, 0, 1)); r = table_set_ellipsize_percent(table, cell, 100); if (r < 0) @@ -46,14 +40,14 @@ static int test_calendar_one(usec_t n, const char *p) { if (!streq(t, p)) { r = table_add_many(table, - TABLE_STRING, "Original form:", + TABLE_FIELD, "Original form", TABLE_STRING, p); if (r < 0) return table_log_add_error(r); } r = table_add_many(table, - TABLE_STRING, "Normalized form:", + TABLE_FIELD, "Normalized form", TABLE_STRING, t); if (r < 0) return table_log_add_error(r); @@ -65,7 +59,7 @@ static int test_calendar_one(usec_t n, const char *p) { if (r == -ENOENT) { if (i == 0) { r = table_add_many(table, - TABLE_STRING, "Next elapse:", + TABLE_FIELD, "Next elapse", TABLE_STRING, "never", TABLE_SET_COLOR, ansi_highlight_yellow()); if (r < 0) @@ -78,7 +72,7 @@ static int test_calendar_one(usec_t n, const char *p) { if (i == 0) { r = table_add_many(table, - TABLE_STRING, "Next elapse:", + TABLE_FIELD, "Next elapse", TABLE_TIMESTAMP, next, TABLE_SET_COLOR, ansi_highlight_blue()); if (r < 0) @@ -91,7 +85,7 @@ static int test_calendar_one(usec_t n, const char *p) { else k = 0; - r = table_add_cell_stringf(table, NULL, "Iteration #%u:", i+1); + r = table_add_cell_stringf_full(table, NULL, TABLE_FIELD, "Iteration #%u", i+1); if (r < 0) return table_log_add_error(r); @@ -104,14 +98,14 @@ static int test_calendar_one(usec_t n, const char *p) { if (!in_utc_timezone()) { r = table_add_many(table, - TABLE_STRING, "(in UTC):", + TABLE_FIELD, "(in UTC)", TABLE_TIMESTAMP_UTC, next); if (r < 0) return table_log_add_error(r); } r = table_add_many(table, - TABLE_STRING, "From now:", + TABLE_FIELD, "From now", TABLE_TIMESTAMP_RELATIVE, next); if (r < 0) return table_log_add_error(r); From 1ba1348182874dcb7e6b7b5dfbf8dce4de542d7f Mon Sep 17 00:00:00 2001 From: David Tardon Date: Fri, 11 Nov 2022 09:17:20 +0100 Subject: [PATCH 3/7] analyze-timestamp: port to vertical table --- src/analyze/analyze-timestamp.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/analyze/analyze-timestamp.c b/src/analyze/analyze-timestamp.c index 79764e014e..97de4387ab 100644 --- a/src/analyze/analyze-timestamp.c +++ b/src/analyze/analyze-timestamp.c @@ -18,30 +18,24 @@ static int test_timestamp_one(const char *p) { return r; } - table = table_new("name", "value"); + table = table_new_vertical(); if (!table) return log_oom(); - table_set_header(table, false); - assert_se(cell = table_get_cell(table, 0, 0)); r = table_set_ellipsize_percent(table, cell, 100); if (r < 0) return r; - r = table_set_align_percent(table, cell, 100); - if (r < 0) - return r; - assert_se(cell = table_get_cell(table, 0, 1)); r = table_set_ellipsize_percent(table, cell, 100); if (r < 0) return r; r = table_add_many(table, - TABLE_STRING, "Original form:", + TABLE_FIELD, "Original form", TABLE_STRING, p, - TABLE_STRING, "Normalized form:", + TABLE_FIELD, "Normalized form", TABLE_TIMESTAMP, usec, TABLE_SET_COLOR, ansi_highlight_blue()); if (r < 0) @@ -49,13 +43,13 @@ static int test_timestamp_one(const char *p) { if (!in_utc_timezone()) { r = table_add_many(table, - TABLE_STRING, "(in UTC):", + TABLE_FIELD, "(in UTC)", TABLE_TIMESTAMP_UTC, usec); if (r < 0) return table_log_add_error(r); } - r = table_add_cell(table, NULL, TABLE_STRING, "UNIX seconds:"); + r = table_add_cell(table, NULL, TABLE_FIELD, "UNIX seconds"); if (r < 0) return table_log_add_error(r); @@ -70,7 +64,7 @@ static int test_timestamp_one(const char *p) { return r; r = table_add_many(table, - TABLE_STRING, "From now:", + TABLE_FIELD, "From now", TABLE_TIMESTAMP_RELATIVE, usec); if (r < 0) return table_log_add_error(r); From 9e1344850fbb33cf8c084ab3042b95815fa43aa6 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Fri, 11 Nov 2022 09:42:52 +0100 Subject: [PATCH 4/7] analyze-timespan: port to vertical table --- src/analyze/analyze-timespan.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/analyze/analyze-timespan.c b/src/analyze/analyze-timespan.c index f244ace04a..3fdf0f964c 100644 --- a/src/analyze/analyze-timespan.c +++ b/src/analyze/analyze-timespan.c @@ -22,39 +22,33 @@ int verb_timespan(int argc, char *argv[], void *userdata) { return r; } - table = table_new("name", "value"); + table = table_new_vertical(); if (!table) return log_oom(); - table_set_header(table, false); - assert_se(cell = table_get_cell(table, 0, 0)); r = table_set_ellipsize_percent(table, cell, 100); if (r < 0) return r; - r = table_set_align_percent(table, cell, 100); - if (r < 0) - return r; - assert_se(cell = table_get_cell(table, 0, 1)); r = table_set_ellipsize_percent(table, cell, 100); if (r < 0) return r; r = table_add_many(table, - TABLE_STRING, "Original:", + TABLE_FIELD, "Original", TABLE_STRING, *input_timespan); if (r < 0) return table_log_add_error(r); - r = table_add_cell_stringf(table, NULL, "%ss:", special_glyph(SPECIAL_GLYPH_MU)); + r = table_add_cell_stringf_full(table, NULL, TABLE_FIELD, "%ss", special_glyph(SPECIAL_GLYPH_MU)); if (r < 0) return table_log_add_error(r); r = table_add_many(table, TABLE_UINT64, output_usecs, - TABLE_STRING, "Human:", + TABLE_FIELD, "Human", TABLE_TIMESPAN, output_usecs, TABLE_SET_COLOR, ansi_highlight()); if (r < 0) From 9c1b0927d3611750a5841906142a784bcc11af23 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Fri, 11 Nov 2022 09:53:10 +0100 Subject: [PATCH 5/7] analyze-inspect-elf: port to vertical table --- src/analyze/analyze-inspect-elf.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/src/analyze/analyze-inspect-elf.c b/src/analyze/analyze-inspect-elf.c index 155c611c71..da2c64565a 100644 --- a/src/analyze/analyze-inspect-elf.c +++ b/src/analyze/analyze-inspect-elf.c @@ -34,7 +34,7 @@ static int analyze_elf(char **filenames, JsonFormatFlags json_flags) { if (r < 0) return log_error_errno(r, "Parsing \"%s\" as ELF object failed: %m", abspath); - t = table_new("", ""); + t = table_new_vertical(); if (!t) return log_oom(); @@ -44,7 +44,7 @@ static int analyze_elf(char **filenames, JsonFormatFlags json_flags) { r = table_add_many( t, - TABLE_STRING, "path:", + TABLE_FIELD, "path", TABLE_STRING, abspath); if (r < 0) return table_log_add_error(r); @@ -62,15 +62,9 @@ static int analyze_elf(char **filenames, JsonFormatFlags json_flags) { * metadata is parsed recursively in core files, so there might be * multiple modules. */ if (STR_IN_SET(module_name, "elfType", "elfArchitecture")) { - _cleanup_free_ char *suffixed = NULL; - - suffixed = strjoin(module_name, ":"); - if (!suffixed) - return log_oom(); - r = table_add_many( t, - TABLE_STRING, suffixed, + TABLE_FIELD, module_name, TABLE_STRING, json_variant_string(module_json)); if (r < 0) return table_log_add_error(r); @@ -91,7 +85,7 @@ static int analyze_elf(char **filenames, JsonFormatFlags json_flags) { if (!streq(abspath, module_name)) { r = table_add_many( t, - TABLE_STRING, "module name:", + TABLE_FIELD, "module name", TABLE_STRING, module_name); if (r < 0) return table_log_add_error(r); @@ -99,15 +93,9 @@ static int analyze_elf(char **filenames, JsonFormatFlags json_flags) { JSON_VARIANT_OBJECT_FOREACH(field_name, field, module_json) if (json_variant_is_string(field)) { - _cleanup_free_ char *suffixed = NULL; - - suffixed = strjoin(field_name, ":"); - if (!suffixed) - return log_oom(); - r = table_add_many( t, - TABLE_STRING, suffixed, + TABLE_FIELD, field_name, TABLE_STRING, json_variant_string(field)); if (r < 0) return table_log_add_error(r); @@ -115,8 +103,6 @@ static int analyze_elf(char **filenames, JsonFormatFlags json_flags) { } } if (json_flags & JSON_FORMAT_OFF) { - (void) table_set_header(t, true); - r = table_print(t, NULL); if (r < 0) return table_log_print_error(r); From fa09e364237afb8cbf2eb90b001ef938e7f3a9eb Mon Sep 17 00:00:00 2001 From: David Tardon Date: Fri, 11 Nov 2022 09:57:10 +0100 Subject: [PATCH 6/7] hostnamectl: port to vertical table --- src/hostname/hostnamectl.c | 39 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index 826826d70b..52606d2f40 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -82,20 +82,17 @@ static int print_status_info(StatusInfo *i) { assert(i); - table = table_new("key", "value"); + table = table_new_vertical(); if (!table) return log_oom(); assert_se(cell = table_get_cell(table, 0, 0)); (void) table_set_ellipsize_percent(table, cell, 100); - (void) table_set_align_percent(table, cell, 100); - - table_set_header(table, false); table_set_ersatz_string(table, TABLE_ERSATZ_UNSET); r = table_add_many(table, - TABLE_STRING, "Static hostname:", + TABLE_FIELD, "Static hostname", TABLE_STRING, i->static_hostname); if (r < 0) return table_log_add_error(r); @@ -103,7 +100,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->pretty_hostname) && !streq_ptr(i->pretty_hostname, i->static_hostname)) { r = table_add_many(table, - TABLE_STRING, "Pretty hostname:", + TABLE_FIELD, "Pretty hostname", TABLE_STRING, i->pretty_hostname); if (r < 0) return table_log_add_error(r); @@ -112,7 +109,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->hostname) && !streq_ptr(i->hostname, i->static_hostname)) { r = table_add_many(table, - TABLE_STRING, "Transient hostname:", + TABLE_FIELD, "Transient hostname", TABLE_STRING, i->hostname); if (r < 0) return table_log_add_error(r); @@ -120,7 +117,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->icon_name)) { r = table_add_many(table, - TABLE_STRING, "Icon name:", + TABLE_FIELD, "Icon name", TABLE_STRING, i->icon_name); if (r < 0) return table_log_add_error(r); @@ -134,7 +131,7 @@ static int print_status_info(StatusInfo *i) { v = strjoina(i->chassis, " ", v); r = table_add_many(table, - TABLE_STRING, "Chassis:", + TABLE_FIELD, "Chassis", TABLE_STRING, v ?: i->chassis); if (r < 0) return table_log_add_error(r); @@ -142,7 +139,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->deployment)) { r = table_add_many(table, - TABLE_STRING, "Deployment:", + TABLE_FIELD, "Deployment", TABLE_STRING, i->deployment); if (r < 0) return table_log_add_error(r); @@ -150,7 +147,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->location)) { r = table_add_many(table, - TABLE_STRING, "Location:", + TABLE_FIELD, "Location", TABLE_STRING, i->location); if (r < 0) return table_log_add_error(r); @@ -159,7 +156,7 @@ static int print_status_info(StatusInfo *i) { r = sd_id128_get_machine(&mid); if (r >= 0) { r = table_add_many(table, - TABLE_STRING, "Machine ID:", + TABLE_FIELD, "Machine ID", TABLE_ID128, mid); if (r < 0) return table_log_add_error(r); @@ -168,7 +165,7 @@ static int print_status_info(StatusInfo *i) { r = sd_id128_get_boot(&bid); if (r >= 0) { r = table_add_many(table, - TABLE_STRING, "Boot ID:", + TABLE_FIELD, "Boot ID", TABLE_ID128, bid); if (r < 0) return table_log_add_error(r); @@ -176,7 +173,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->virtualization)) { r = table_add_many(table, - TABLE_STRING, "Virtualization:", + TABLE_FIELD, "Virtualization", TABLE_STRING, i->virtualization); if (r < 0) return table_log_add_error(r); @@ -184,7 +181,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->os_pretty_name)) { r = table_add_many(table, - TABLE_STRING, "Operating System:", + TABLE_FIELD, "Operating System", TABLE_STRING, i->os_pretty_name, TABLE_SET_URL, i->home_url); if (r < 0) @@ -193,7 +190,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->os_cpe_name)) { r = table_add_many(table, - TABLE_STRING, "CPE OS Name:", + TABLE_FIELD, "CPE OS Name", TABLE_STRING, i->os_cpe_name); if (r < 0) return table_log_add_error(r); @@ -204,7 +201,7 @@ static int print_status_info(StatusInfo *i) { v = strjoina(i->kernel_name, " ", i->kernel_release); r = table_add_many(table, - TABLE_STRING, "Kernel:", + TABLE_FIELD, "Kernel", TABLE_STRING, v); if (r < 0) return table_log_add_error(r); @@ -212,7 +209,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->architecture)) { r = table_add_many(table, - TABLE_STRING, "Architecture:", + TABLE_FIELD, "Architecture", TABLE_STRING, i->architecture); if (r < 0) return table_log_add_error(r); @@ -220,7 +217,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->hardware_vendor)) { r = table_add_many(table, - TABLE_STRING, "Hardware Vendor:", + TABLE_FIELD, "Hardware Vendor", TABLE_STRING, i->hardware_vendor); if (r < 0) return table_log_add_error(r); @@ -228,7 +225,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->hardware_model)) { r = table_add_many(table, - TABLE_STRING, "Hardware Model:", + TABLE_FIELD, "Hardware Model", TABLE_STRING, i->hardware_model); if (r < 0) return table_log_add_error(r); @@ -236,7 +233,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->firmware_version)) { r = table_add_many(table, - TABLE_STRING, "Firmware Version:", + TABLE_FIELD, "Firmware Version", TABLE_STRING, i->firmware_version); if (r < 0) return table_log_add_error(r); From c62ca82656acb89093060e610613bea2bad3b097 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Fri, 11 Nov 2022 09:59:09 +0100 Subject: [PATCH 7/7] localectl: port to vertical table --- src/locale/localectl.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/locale/localectl.c b/src/locale/localectl.c index e44e287282..9a4e4fb59b 100644 --- a/src/locale/localectl.c +++ b/src/locale/localectl.c @@ -72,15 +72,12 @@ static int print_status_info(StatusInfo *i) { return log_error_errno(r, "Failed to build locale settings from kernel command line: %m"); } - table = table_new("key", "value"); + table = table_new_vertical(); if (!table) return log_oom(); assert_se(cell = table_get_cell(table, 0, 0)); (void) table_set_ellipsize_percent(table, cell, 100); - (void) table_set_align_percent(table, cell, 100); - - table_set_header(table, false); table_set_ersatz_string(table, TABLE_ERSATZ_UNSET); @@ -96,30 +93,30 @@ static int print_status_info(StatusInfo *i) { } r = table_add_many(table, - TABLE_STRING, "System Locale:", + TABLE_FIELD, "System Locale", TABLE_STRV, i->locale, - TABLE_STRING, "VC Keymap:", + TABLE_FIELD, "VC Keymap", TABLE_STRING, i->vconsole_keymap); if (r < 0) return table_log_add_error(r); if (!isempty(i->vconsole_keymap_toggle)) { r = table_add_many(table, - TABLE_STRING, "VC Toggle Keymap:", + TABLE_FIELD, "VC Toggle Keymap", TABLE_STRING, i->vconsole_keymap_toggle); if (r < 0) return table_log_add_error(r); } r = table_add_many(table, - TABLE_STRING, "X11 Layout:", + TABLE_FIELD, "X11 Layout", TABLE_STRING, i->x11_layout); if (r < 0) return table_log_add_error(r); if (!isempty(i->x11_model)) { r = table_add_many(table, - TABLE_STRING, "X11 Model:", + TABLE_FIELD, "X11 Model", TABLE_STRING, i->x11_model); if (r < 0) return table_log_add_error(r); @@ -127,7 +124,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->x11_variant)) { r = table_add_many(table, - TABLE_STRING, "X11 Variant:", + TABLE_FIELD, "X11 Variant", TABLE_STRING, i->x11_variant); if (r < 0) return table_log_add_error(r); @@ -135,7 +132,7 @@ static int print_status_info(StatusInfo *i) { if (!isempty(i->x11_options)) { r = table_add_many(table, - TABLE_STRING, "X11 Options:", + TABLE_FIELD, "X11 Options", TABLE_STRING, i->x11_options); if (r < 0) return table_log_add_error(r);