Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame] | 1 | From 90271bd69a7488714a51173dcec3f349459761c9 Mon Sep 17 00:00:00 2001 |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 2 | From: Tomas Pecka <peckato1@users.noreply.github.com> |
| 3 | Date: Thu, 7 Oct 2021 14:16:53 +0200 |
| 4 | Subject: [PATCH 6/9] networkctl: lldp table now ellpsizes via table functions |
| 5 | |
| 6 | Tables can now ellipize on their own so there is no need to manually |
| 7 | call ellpsize on the table data. |
| 8 | |
| 9 | To achieve compatibility with previous versions the table columns are |
| 10 | set to have the exact same size as before, therefore the minimum and |
| 11 | maximum widths for the columns in the output. |
| 12 | --- |
| 13 | src/network/networkctl.c | 32 +++++++------------------------- |
| 14 | 1 file changed, 7 insertions(+), 25 deletions(-) |
| 15 | |
| 16 | diff --git a/src/network/networkctl.c b/src/network/networkctl.c |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame] | 17 | index 30cd75eec0..46c08b5549 100644 |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 18 | --- a/src/network/networkctl.c |
| 19 | +++ b/src/network/networkctl.c |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame] | 20 | @@ -2513,21 +2513,27 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) { |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 21 | |
| 22 | assert_se(cell = table_get_cell(table, 0, 0)); |
| 23 | table_set_minimum_width(table, cell, 16); |
| 24 | + table_set_maximum_width(table, cell, 16); |
| 25 | |
| 26 | assert_se(cell = table_get_cell(table, 0, 1)); |
| 27 | table_set_minimum_width(table, cell, 17); |
| 28 | + table_set_maximum_width(table, cell, 17); |
| 29 | |
| 30 | assert_se(cell = table_get_cell(table, 0, 2)); |
| 31 | table_set_minimum_width(table, cell, 16); |
| 32 | + table_set_maximum_width(table, cell, 16); |
| 33 | |
| 34 | assert_se(cell = table_get_cell(table, 0, 3)); |
| 35 | table_set_minimum_width(table, cell, 11); |
| 36 | + table_set_maximum_width(table, cell, 11); |
| 37 | |
| 38 | assert_se(cell = table_get_cell(table, 0, 4)); |
| 39 | table_set_minimum_width(table, cell, 17); |
| 40 | + table_set_maximum_width(table, cell, 17); |
| 41 | |
| 42 | assert_se(cell = table_get_cell(table, 0, 5)); |
| 43 | table_set_minimum_width(table, cell, 16); |
| 44 | + table_set_maximum_width(table, cell, 16); |
| 45 | |
| 46 | if (table_set_empty_string(table, "n/a") < 0) |
| 47 | return log_oom(); |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame] | 48 | @@ -2544,7 +2550,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) { |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | for (;;) { |
| 52 | - _cleanup_free_ char *cid = NULL, *pid = NULL, *sname = NULL, *pdesc = NULL, *capabilities = NULL; |
| 53 | + _cleanup_free_ char *capabilities = NULL; |
| 54 | const char *chassis_id = NULL, *port_id = NULL, *system_name = NULL, *port_description = NULL; |
| 55 | _cleanup_(sd_lldp_neighbor_unrefp) sd_lldp_neighbor *n = NULL; |
| 56 | uint16_t cc; |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame] | 57 | @@ -2562,30 +2568,6 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) { |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 58 | (void) sd_lldp_neighbor_get_system_name(n, &system_name); |
| 59 | (void) sd_lldp_neighbor_get_port_description(n, &port_description); |
| 60 | |
| 61 | - if (chassis_id) { |
| 62 | - cid = ellipsize(chassis_id, 17, 100); |
| 63 | - if (cid) |
| 64 | - chassis_id = cid; |
| 65 | - } |
| 66 | - |
| 67 | - if (port_id) { |
| 68 | - pid = ellipsize(port_id, 17, 100); |
| 69 | - if (pid) |
| 70 | - port_id = pid; |
| 71 | - } |
| 72 | - |
| 73 | - if (system_name) { |
| 74 | - sname = ellipsize(system_name, 16, 100); |
| 75 | - if (sname) |
| 76 | - system_name = sname; |
| 77 | - } |
| 78 | - |
| 79 | - if (port_description) { |
| 80 | - pdesc = ellipsize(port_description, 16, 100); |
| 81 | - if (pdesc) |
| 82 | - port_description = pdesc; |
| 83 | - } |
| 84 | - |
| 85 | if (sd_lldp_neighbor_get_enabled_capabilities(n, &cc) >= 0) { |
| 86 | capabilities = lldp_capabilities_to_string(cc); |
| 87 | all |= cc; |
| 88 | -- |
Václav Kubernát | 8cd6156 | 2021-12-08 13:27:31 +0100 | [diff] [blame] | 89 | 2.34.1 |
Tomáš Pecka | ae30176 | 2021-10-13 10:50:37 +0200 | [diff] [blame] | 90 | |