[systemd-devel] [PATCH] systemctl: make LOAD column width dynamic
Mantas Mikulėnas
grawity at gmail.com
Mon Nov 4 13:01:17 PST 2013
Otherwise 'not-found' overflows into the ACTIVE column.
---
src/systemctl/systemctl.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 9f5e273..04699be 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -287,11 +287,13 @@ static bool output_show_unit(const struct unit_info *u) {
}
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
- unsigned id_len, max_id_len, active_len, sub_len, job_len, desc_len, n_shown = 0;
+ unsigned id_len, max_id_len, load_len, active_len, sub_len, job_len, desc_len;
+ unsigned n_shown = 0;
const struct unit_info *u;
int job_count = 0;
max_id_len = sizeof("UNIT")-1;
+ load_len = sizeof("LOAD")-1;
active_len = sizeof("ACTIVE")-1;
sub_len = sizeof("SUB")-1;
job_len = sizeof("JOB")-1;
@@ -302,6 +304,7 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
continue;
max_id_len = MAX(max_id_len, strlen(u->id));
+ load_len = MAX(load_len, strlen(u->load_state));
active_len = MAX(active_len, strlen(u->active_state));
sub_len = MAX(sub_len, strlen(u->sub_state));
if (u->job_id != 0) {
@@ -344,7 +347,7 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
continue;
if (!n_shown && !arg_no_legend) {
- printf("%-*s %-6s %-*s %-*s ", id_len, "UNIT", "LOAD",
+ printf("%-*s %-*s %-*s %-*s ", id_len, "UNIT", load_len, "LOAD",
active_len, "ACTIVE", sub_len, "SUB");
if (job_count)
printf("%-*s ", job_len, "JOB");
@@ -371,9 +374,9 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
e = arg_full ? NULL : ellipsize(u->id, id_len, 33);
- printf("%s%-*s%s %s%-6s%s %s%-*s %-*s%s %-*s",
+ printf("%s%-*s%s %s%-*s%s %s%-*s %-*s%s %-*s",
on, id_len, e ? e : u->id, off,
- on_loaded, u->load_state, off_loaded,
+ on_loaded, load_len, u->load_state, off_loaded,
on_active, active_len, u->active_state,
sub_len, u->sub_state, off_active,
job_count ? job_len + 1 : 0, u->job_id ? u->job_type : "");
--
1.8.4.2
More information about the systemd-devel
mailing list