mirror of
https://github.com/systemd/systemd.git
synced 2024-10-29 21:55:36 +03:00
systemctl: move printing of state to the printing func.
No functional change, just refactoring.
This commit is contained in:
parent
c6b9baaa5b
commit
7a26ed2ae2
@ -8,11 +8,36 @@
|
|||||||
#include "systemctl.h"
|
#include "systemctl.h"
|
||||||
#include "terminal-util.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;
|
_cleanup_free_ char *n = NULL;
|
||||||
size_t max_len = MAX(columns(),20u);
|
size_t max_len = MAX(columns(),20u);
|
||||||
size_t len = 0;
|
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) {
|
if (!arg_plain) {
|
||||||
for (int i = level - 1; i >= 0; i--) {
|
for (int i = level - 1; i >= 0; i--) {
|
||||||
len += 2;
|
len += 2;
|
||||||
@ -108,32 +133,7 @@ static int list_dependencies_one(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arg_plain)
|
r = list_dependencies_print(*c, active_state, level, branches, /* last = */ c[1] == NULL && !circular);
|
||||||
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);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
@ -145,8 +145,7 @@ static int list_dependencies_one(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (circular && !arg_plain) {
|
if (circular && !arg_plain) {
|
||||||
printf(" ");
|
r = list_dependencies_print("...", _UNIT_ACTIVE_STATE_INVALID, level, branches, /* last = */ true);
|
||||||
r = list_dependencies_print("...", level, branches, /* last = */ true);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user