diff options
author | David Tardon <dtardon@redhat.com> | 2023-03-17 10:43:54 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2023-03-17 14:50:40 +0100 |
commit | 7a26ed2ae2afc06b8ac6e3ccc280bbc286e28a8c (patch) | |
tree | 58328b3683ec50a7f4ff4590dc930b3251440f69 | |
parent | c6b9baaa5bae96e1c7df6376154147f6570fa563 (diff) | |
download | systemd-7a26ed2ae2afc06b8ac6e3ccc280bbc286e28a8c.tar.gz |
systemctl: move printing of state to the printing func.
No functional change, just refactoring.
-rw-r--r-- | src/systemctl/systemctl-list-dependencies.c | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/src/systemctl/systemctl-list-dependencies.c b/src/systemctl/systemctl-list-dependencies.c index 7953943223..a9121f1035 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; } |