From 7b376b29a3e1d0b9613474de2f2aa32705031b12 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 18 Jan 2021 06:36:02 +0900 Subject: [PATCH 1/4] log: use ansi_normal() instead of ANSI_NORMAL --- src/basic/log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/log.c b/src/basic/log.c index 53f8df634f..665dbf40a5 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -405,7 +405,7 @@ static int write_to_console( const char *lon = "", *loff = ""; if (log_get_show_color()) { lon = ansi_highlight_yellow4(); - loff = ANSI_NORMAL; + loff = ansi_normal(); } (void) snprintf(location, sizeof location, "%s%s:%i%s: ", lon, file, line, loff); From bb146d238fbd65569cc996662beccccbfd184fc9 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 18 Jan 2021 06:36:42 +0900 Subject: [PATCH 2/4] terminal-util: use ansi_normal() or friends instead of ANSI_NORMAL --- src/basic/terminal-util.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 3fc03050ac..fc63e134c3 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -1375,23 +1375,23 @@ void get_log_colors(int priority, const char **on, const char **off, const char if (on) *on = ansi_highlight_red(); if (off) - *off = ANSI_NORMAL; + *off = ansi_normal(); if (highlight) - *highlight = ANSI_HIGHLIGHT; + *highlight = ansi_highlight(); } else if (priority <= LOG_WARNING) { if (on) *on = ansi_highlight_yellow(); if (off) - *off = ANSI_NORMAL; + *off = ansi_normal(); if (highlight) - *highlight = ANSI_HIGHLIGHT; + *highlight = ansi_highlight(); } else if (priority <= LOG_NOTICE) { if (on) - *on = ANSI_HIGHLIGHT; + *on = ansi_highlight(); if (off) - *off = ANSI_NORMAL; + *off = ansi_normal(); if (highlight) *highlight = ansi_highlight_red(); @@ -1399,7 +1399,7 @@ void get_log_colors(int priority, const char **on, const char **off, const char if (on) *on = ansi_grey(); if (off) - *off = ANSI_NORMAL; + *off = ansi_normal(); if (highlight) *highlight = ansi_highlight_red(); } From cd7ae1b44e48b4658476d65fe4b104a75ef05d43 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 18 Jan 2021 06:37:18 +0900 Subject: [PATCH 3/4] logs-show: simplify code --- src/shared/logs-show.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 6a1810888c..e60ee50e1c 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -66,26 +66,17 @@ static int print_catalog(FILE *f, sd_journal *j) { else prefix = "--"; - if (colors_enabled()) - newline = strjoina(ANSI_NORMAL "\n", ansi_grey(), prefix, ANSI_NORMAL " ", ansi_green()); - else - newline = strjoina("\n", prefix, " "); + newline = strjoina(ansi_normal(), "\n", ansi_grey(), prefix, ansi_normal(), " ", ansi_green()); z = strreplace(strstrip(t), "\n", newline); if (!z) return log_oom(); - if (colors_enabled()) - fprintf(f, "%s%s %s%s", ansi_grey(), prefix, ANSI_NORMAL, ansi_green()); - else - fprintf(f, "%s ", prefix); + fprintf(f, "%s%s %s%s", ansi_grey(), prefix, ansi_normal(), ansi_green()); fputs(z, f); - if (colors_enabled()) - fputs(ANSI_NORMAL "\n", f); - else - fputc('\n', f); + fprintf(f, "%s\n", ansi_normal()); return 1; } From 6d533e56f8f954a9e0c59ecc570ccec69d34bcc2 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 18 Jan 2021 06:38:13 +0900 Subject: [PATCH 4/4] cgtop: use ansi_normal() or friends instead of ANSI_NORMAL --- src/cgtop/cgtop.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index e9e7ed2734..9c96b4d697 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -1080,14 +1080,12 @@ static int run(int argc, char *argv[]) { case '?': case 'h': -#define ON ANSI_HIGHLIGHT -#define OFF ANSI_NORMAL - fprintf(stdout, - "\t<" ON "p" OFF "> By path; <" ON "t" OFF "> By tasks/procs; <" ON "c" OFF "> By CPU; <" ON "m" OFF "> By memory; <" ON "i" OFF "> By I/O\n" - "\t<" ON "+" OFF "> Inc. delay; <" ON "-" OFF "> Dec. delay; <" ON "%%" OFF "> Toggle time; <" ON "SPACE" OFF "> Refresh\n" - "\t<" ON "P" OFF "> Toggle count userspace processes; <" ON "k" OFF "> Toggle count all processes\n" - "\t<" ON "r" OFF "> Count processes recursively; <" ON "q" OFF "> Quit"); + "\t<%1$sp%2$s> By path; <%1$st%2$s> By tasks/procs; <%1$sc%2$s> By CPU; <%1$sm%2$s> By memory; <%1$si%2$s> By I/O\n" + "\t<%1$s+%2$s> Inc. delay; <%1$s-%2$s> Dec. delay; <%1$s%%%2$s> Toggle time; <%1$sSPACE%2$s> Refresh\n" + "\t<%1$sP%2$s> Toggle count userspace processes; <%1$sk%2$s> Toggle count all processes\n" + "\t<%1$sr%2$s> Count processes recursively; <%1$sq%2$s> Quit", + ansi_highlight(), ansi_normal()); fflush(stdout); sleep(3); break;