From: Lennart Poettering Date: Tue, 5 Sep 2017 14:31:26 +0000 (+0200) Subject: systemctl: make sure we properly turn off color at the end of each line of "list... X-Git-Tag: v235~159 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=aaa6732d7834c1dc0f937936563218724d71b619;p=platform%2Fupstream%2Fsystemd.git 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 --- diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index bffc9e7..318cd35 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -1435,39 +1435,36 @@ static void output_unit_file_list(const UnitFileList *units, unsigned c) { ansi_normal()); for (u = units; u < units + c; u++) { + const char *on_underline = NULL, *on_color = NULL, *off = NULL, *id; _cleanup_free_ char *e = NULL; - const char *on, *off, *on_underline = "", *off_underline = ""; - const char *id; - bool underline = false; + bool underline; + + underline = u + 1 < units + c && + !streq(unit_type_suffix(u->path), unit_type_suffix((u + 1)->path)); - if (u + 1 < units + c && - !streq(unit_type_suffix(u->path), unit_type_suffix((u + 1)->path))) { + if (underline) on_underline = ansi_underline(); - off_underline = ansi_normal(); - underline = true; - } if (IN_SET(u->state, UNIT_FILE_MASKED, UNIT_FILE_MASKED_RUNTIME, UNIT_FILE_DISABLED, 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) - on = underline ? ansi_highlight_green_underline() : ansi_highlight_green(); - else - on = on_underline; - off = off_underline; + on_color = underline ? ansi_highlight_green_underline() : ansi_highlight_green(); + + if (on_underline || on_color) + off = ansi_normal(); id = basename(u->path); e = arg_full ? NULL : ellipsize(id, id_cols, 33); - printf("%s%-*s %s%-*s%s%s\n", - on_underline, + printf("%s%-*s %s%-*s%s\n", + strempty(on_underline), id_cols, e ? e : id, - on, state_cols, unit_file_state_to_string(u->state), off, - off_underline); + strempty(on_color), state_cols, unit_file_state_to_string(u->state), strempty(off)); } if (!arg_no_legend)