1
0
mirror of https://github.com/systemd/systemd.git synced 2025-08-24 09:49:49 +03:00

systemctl: make sure we properly turn off color at the end of each line of "list-unit-files" (#6688)

Let's simplify the code a bit, and make sure we always turn off color
and underlining again on each line, if we used it.

Fixes: #6684
This commit is contained in:
Lennart Poettering
2017-09-05 16:31:26 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent ead36ce651
commit aaa6732d78

View File

@ -1435,39 +1435,36 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) {
ansi_normal()); ansi_normal());
for (u = units; u < units + c; u++) { for (u = units; u < units + c; u++) {
const char *on_underline = NULL, *on_color = NULL, *off = NULL, *id;
_cleanup_free_ char *e = NULL; _cleanup_free_ char *e = NULL;
const char *on, *off, *on_underline = "", *off_underline = ""; bool underline;
const char *id;
bool underline = false;
if (u + 1 < units + c && underline = u + 1 < units + c &&
!streq(unit_type_suffix(u->path), unit_type_suffix((u + 1)->path))) { !streq(unit_type_suffix(u->path), unit_type_suffix((u + 1)->path));
if (underline)
on_underline = ansi_underline(); on_underline = ansi_underline();
off_underline = ansi_normal();
underline = true;
}
if (IN_SET(u->state, if (IN_SET(u->state,
UNIT_FILE_MASKED, UNIT_FILE_MASKED,
UNIT_FILE_MASKED_RUNTIME, UNIT_FILE_MASKED_RUNTIME,
UNIT_FILE_DISABLED, UNIT_FILE_DISABLED,
UNIT_FILE_BAD)) UNIT_FILE_BAD))
on = underline ? ansi_highlight_red_underline() : ansi_highlight_red(); on_color = underline ? ansi_highlight_red_underline() : ansi_highlight_red();
else if (u->state == UNIT_FILE_ENABLED) else if (u->state == UNIT_FILE_ENABLED)
on = underline ? ansi_highlight_green_underline() : ansi_highlight_green(); on_color = underline ? ansi_highlight_green_underline() : ansi_highlight_green();
else
on = on_underline; if (on_underline || on_color)
off = off_underline; off = ansi_normal();
id = basename(u->path); id = basename(u->path);
e = arg_full ? NULL : ellipsize(id, id_cols, 33); e = arg_full ? NULL : ellipsize(id, id_cols, 33);
printf("%s%-*s %s%-*s%s%s\n", printf("%s%-*s %s%-*s%s\n",
on_underline, strempty(on_underline),
id_cols, e ? e : id, id_cols, e ? e : id,
on, state_cols, unit_file_state_to_string(u->state), off, strempty(on_color), state_cols, unit_file_state_to_string(u->state), strempty(off));
off_underline);
} }
if (!arg_no_legend) if (!arg_no_legend)