The first column is given the width of the widest entry, if possible, otherwise all entries are ellipsized to fit in ($COLUMNS - (width of second column)). --- src/systemctl.c | 21 ++++++++++++++++----- 1 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/src/systemctl.c b/src/systemctl.c index 0de2444..1604afa 100644 --- a/src/systemctl.c +++ b/src/systemctl.c @@ -554,8 +554,19 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) { unsigned n_shown = 0; const UnitFileList *u; + const int state_cols = 8; // "DISABLED" seems to be the longest + int id_cols; + + int longest = 0; + for (u = units; u < units + c; u++) { + int len = strlen(file_name_from_path(u->path)); + longest = MAX(longest, len); + } + id_cols = MIN(columns() - state_cols - 1, longest); + id_cols = MAX(id_cols, 9); // "UNIT FILE" + if (on_tty()) - printf("%-25s %-6s\n", "UNIT FILE", "STATE"); + printf("%-*s %-*s\n", id_cols, "UNIT FILE", state_cols, "STATE"); for (u = units; u < units + c; u++) { char *e; @@ -580,11 +591,11 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) { id = file_name_from_path(u->path); - e = arg_full ? NULL : ellipsize(id, 25, 33); + e = arg_full ? NULL : ellipsize(id, id_cols, 33); - printf("%-25s %s%-6s%s\n", - e ? e : id, - on, unit_file_state_to_string(u->state), off); + printf("%-*s %s%-*s%s\n", + id_cols, e ? e : id, + on, state_cols, unit_file_state_to_string(u->state), off); free(e); } -- 1.7.7.308.g2883 _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel