summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2010-09-07 10:30:52 +0200
committerLennart Poettering <lennart@poettering.net>2010-09-14 22:16:28 +0200
commit333302226926abe653f0396db1d76b1f8c4d0fc7 (patch)
tree3aae0c0ec19cff977522be19c4969bdaa5e3a26c /src
parentsystemctl: split job list writing to a seperate function (diff)
downloadsystemd-333302226926abe653f0396db1d76b1f8c4d0fc7.tar.xz
systemd-333302226926abe653f0396db1d76b1f8c4d0fc7.zip
systemctl: limit some column widths to widest actually used
old UNIT LOAD ACTIVE SUB JOB dev-hugepages.automount loaded active running Huge Page dev-mqueue.automount loaded active waiting POSIX Mes proc-sys...misc.automount loaded active waiting Arbitrary sys-kern...ebug.automount loaded active running Debug Fil new UNIT LOAD ACTIVE SUB JOB dev-hugepages.automount loaded active running Huge Pages File System Automount Poi dev-mqueue.automount loaded active waiting POSIX Message Queue File System Auto systemd-shutdownd.socket loaded active listening systemd Delayed Shutdown Socket
Diffstat (limited to 'src')
-rw-r--r--src/systemctl.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/systemctl.c b/src/systemctl.c
index fe55eac25f..fa191abc17 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -251,20 +251,39 @@ static int compare_unit_info(const void *a, const void *b) {
return strcasecmp(u->id, v->id);
}
+static bool output_show_job(const struct unit_info *u) {
+ const char *dot;
+ return (!arg_type || ((dot = strrchr(u->id, '.')) &&
+ streq(dot+1, arg_type))) &&
+ (arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0);
+}
+
static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
+ unsigned active_len, sub_len, job_len;
+
+ active_len = strlen("ACTIVE");
+ sub_len = strlen("SUB");
+ job_len = strlen("JOB");
+ for (const struct unit_info *u = unit_infos; u < unit_infos + c; u++) {
+ if (output_show_job(u)) {
+ active_len = MAX(active_len, strlen(u->active_state));
+ sub_len = MAX(sub_len, strlen(u->sub_state));
+ if (u->job_id != 0)
+ job_len = MAX(job_len, strlen(u->job_type));
+ }
+ }
+
if (on_tty()) {
+ printf("%-25s %-6s %-*s %-*s %-*s", "UNIT", "LOAD",
+ active_len, "ACTIVE", sub_len, "SUB", job_len, "JOB");
if (columns() >= 80+12 || arg_full)
- printf("%-25s %-6s %-12s %-18s %-15s %s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB", "DESCRIPTION");
+ printf(" %s\n", "DESCRIPTION");
else
- printf("%-25s %-6s %-12s %-18s %-15s\n", "UNIT", "LOAD", "ACTIVE", "SUB", "JOB");
+ printf("\n");
}
for (const struct unit_info *u = unit_infos; u < unit_infos + c; u++) {
- const char *dot;
-
- if ((!arg_type || ((dot = strrchr(u->id, '.')) &&
- streq(dot+1, arg_type))) &&
- (arg_all || !(streq(u->active_state, "inactive") || u->following[0]) || u->job_id > 0)) {
+ if (output_show_job(u)) {
char *e;
int a = 0, b = 0;
const char *on_loaded, *off_loaded;
@@ -284,10 +303,11 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
e = arg_full ? NULL : ellipsize(u->id, 25, 33);
- printf("%-25s %s%-6s%s %s%-12s %-18s%s%n",
+ printf("%-25s %s%-6s%s %s%-*s %-*s%s%n",
e ? e : u->id,
on_loaded, u->load_state, off_loaded,
- on_active, u->active_state, u->sub_state, off_active,
+ on_active, active_len, u->active_state,
+ sub_len, u->sub_state, off_active,
&a);
free(e);
@@ -296,13 +316,13 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
a -= strlen(on_active) + strlen(off_active);
if (u->job_id != 0)
- printf(" %-15s%n", u->job_type, &b);
+ printf(" %-*s", job_len, u->job_type);
else
- b = 1 + 15;
+ b = 1 + job_len;
if (a + b + 1 < columns()) {
if (u->job_id == 0)
- printf(" ");
+ printf(" %-*s", job_len, "");
if (arg_full)
printf(" %s", u->description);