From: David Tardon Date: Fri, 17 Mar 2023 09:43:54 +0000 (+0100) Subject: systemctl: move printing of state to the printing func. X-Git-Tag: v254-rc1~973^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7a26ed2ae2afc06b8ac6e3ccc280bbc286e28a8c;p=thirdparty%2Fsystemd.git systemctl: move printing of state to the printing func. No functional change, just refactoring. --- diff --git a/src/systemctl/systemctl-list-dependencies.c b/src/systemctl/systemctl-list-dependencies.c index 7953943223d..a9121f10356 100644 --- a/src/systemctl/systemctl-list-dependencies.c +++ b/src/systemctl/systemctl-list-dependencies.c @@ -8,11 +8,36 @@ #include "systemctl.h" #include "terminal-util.h" -static int list_dependencies_print(const char *name, int level, unsigned branches, bool last) { +static int list_dependencies_print(const char *name, UnitActiveState state, int level, unsigned branches, bool last) { _cleanup_free_ char *n = NULL; size_t max_len = MAX(columns(),20u); size_t len = 0; + if (arg_plain || state == _UNIT_ACTIVE_STATE_INVALID) + printf(" "); + else { + const char *on; + + switch (state) { + case UNIT_ACTIVE: + case UNIT_RELOADING: + case UNIT_ACTIVATING: + on = ansi_highlight_green(); + break; + + case UNIT_INACTIVE: + case UNIT_DEACTIVATING: + on = ansi_normal(); + break; + + default: + on = ansi_highlight_red(); + break; + } + + printf("%s%s%s ", on, special_glyph(unit_active_state_to_glyph(state)), ansi_normal()); + } + if (!arg_plain) { for (int i = level - 1; i >= 0; i--) { len += 2; @@ -108,32 +133,7 @@ static int list_dependencies_one( continue; } - if (arg_plain) - printf(" "); - else { - const char *on; - - switch (active_state) { - case UNIT_ACTIVE: - case UNIT_RELOADING: - case UNIT_ACTIVATING: - on = ansi_highlight_green(); - break; - - case UNIT_INACTIVE: - case UNIT_DEACTIVATING: - on = ansi_normal(); - break; - - default: - on = ansi_highlight_red(); - break; - } - - printf("%s%s%s ", on, special_glyph(unit_active_state_to_glyph(active_state)), ansi_normal()); - } - - r = list_dependencies_print(*c, level, branches, /* last = */ c[1] == NULL && !circular); + r = list_dependencies_print(*c, active_state, level, branches, /* last = */ c[1] == NULL && !circular); if (r < 0) return r; @@ -145,8 +145,7 @@ static int list_dependencies_one( } if (circular && !arg_plain) { - printf(" "); - r = list_dependencies_print("...", level, branches, /* last = */ true); + r = list_dependencies_print("...", _UNIT_ACTIVE_STATE_INVALID, level, branches, /* last = */ true); if (r < 0) return r; }