Merge pull request #25339 from dtardon/vertical-tables
Port more tools to vertical table
This commit is contained in:
@@ -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, "Iter. #%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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
+18
-21
@@ -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);
|
||||
|
||||
+8
-11
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user