[systemd-commits] 2 commits - src/systemctl
Zbigniew JÄdrzejewski-Szmek
zbyszek at kemper.freedesktop.org
Thu Oct 4 04:19:36 PDT 2012
src/systemctl/systemctl.c | 53 +++++++++++++++++++++++++++++++---------------
1 file changed, 36 insertions(+), 17 deletions(-)
New commits:
commit 57f7ae4f68cf9ac72213b9cfc87a362ef631b483
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Thu Oct 4 11:12:23 2012 +0000
systemctl: colorize number of units listed
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 6a42fea..a4290c4 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -186,6 +186,14 @@ static void polkit_agent_open_if_enabled(void) {
}
#endif
+static const char *ansi_highlight(bool b) {
+
+ if (!on_tty())
+ return "";
+
+ return b ? ANSI_HIGHLIGHT_ON : ANSI_HIGHLIGHT_OFF;
+}
+
static const char *ansi_highlight_red(bool b) {
if (!on_tty())
@@ -420,18 +428,28 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
}
if (!arg_no_legend) {
- if (n_shown)
+ const char *on, *off;
+
+ if (n_shown) {
printf("\nLOAD = Reflects whether the unit definition was properly loaded.\n"
"ACTIVE = The high-level unit activation state, i.e. generalization of SUB.\n"
"SUB = The low-level unit activation state, values depend on unit type.\n"
"JOB = Pending job for the unit.\n\n");
+ on = ansi_highlight(true);
+ off = ansi_highlight(false);
+ } else {
+ on = ansi_highlight_red(true);
+ off = ansi_highlight_red(false);
+ }
if (arg_all)
- printf("%u loaded units listed.\n"
- "To show all installed unit files use 'systemctl list-unit-files'.\n", n_shown);
+ printf("%s%u loaded units listed.%s\n"
+ "To show all installed unit files use 'systemctl list-unit-files'.\n",
+ on, n_shown, off);
else
- printf("%u loaded units listed. Pass --all to see loaded but inactive units, too.\n"
- "To show all installed unit files use 'systemctl list-unit-files'.\n", n_shown);
+ printf("%s%u loaded units listed.%s Pass --all to see loaded but inactive units, too.\n"
+ "To show all installed unit files use 'systemctl list-unit-files'.\n",
+ on, n_shown, off);
}
}
commit ad94ad63e31e4822d1cf5b0908be0f3111930ff9
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Thu Oct 4 11:01:10 2012 +0000
systemctl: do not print header if no units listed
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index a4bec49..6a42fea 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -372,15 +372,6 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
} else
id_len = max_id_len;
- if (!arg_no_legend) {
- printf("%-*s %-6s %-*s %-*s %-*s ", id_len, "UNIT", "LOAD",
- active_len, "ACTIVE", sub_len, "SUB", job_len, "JOB");
- if (!arg_full && arg_no_pager)
- printf("%.*s\n", desc_len, "DESCRIPTION");
- else
- printf("%s\n", "DESCRIPTION");
- }
-
for (u = unit_infos; u < unit_infos + c; u++) {
char *e;
const char *on_loaded, *off_loaded;
@@ -389,6 +380,15 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
if (!output_show_unit(u))
continue;
+ if (!n_shown && !arg_no_legend) {
+ printf("%-*s %-6s %-*s %-*s %-*s ", id_len, "UNIT", "LOAD",
+ active_len, "ACTIVE", sub_len, "SUB", job_len, "JOB");
+ if (!arg_full && arg_no_pager)
+ printf("%.*s\n", desc_len, "DESCRIPTION");
+ else
+ printf("%s\n", "DESCRIPTION");
+ }
+
n_shown++;
if (streq(u->load_state, "error")) {
@@ -420,16 +420,17 @@ static void output_units_list(const struct unit_info *unit_infos, unsigned c) {
}
if (!arg_no_legend) {
- printf("\nLOAD = Reflects whether the unit definition was properly loaded.\n"
- "ACTIVE = The high-level unit activation state, i.e. generalization of SUB.\n"
- "SUB = The low-level unit activation state, values depend on unit type.\n"
- "JOB = Pending job for the unit.\n");
+ if (n_shown)
+ printf("\nLOAD = Reflects whether the unit definition was properly loaded.\n"
+ "ACTIVE = The high-level unit activation state, i.e. generalization of SUB.\n"
+ "SUB = The low-level unit activation state, values depend on unit type.\n"
+ "JOB = Pending job for the unit.\n\n");
if (arg_all)
- printf("\n%u loaded units listed.\n"
+ printf("%u loaded units listed.\n"
"To show all installed unit files use 'systemctl list-unit-files'.\n", n_shown);
else
- printf("\n%u loaded units listed. Pass --all to see loaded but inactive units, too.\n"
+ printf("%u loaded units listed. Pass --all to see loaded but inactive units, too.\n"
"To show all installed unit files use 'systemctl list-unit-files'.\n", n_shown);
}
}
More information about the systemd-commits
mailing list