From 924647ebfb3a7af8ad805b0df749ce4787a2d3cd Mon Sep 17 00:00:00 2001 From: Daniel Schaal Date: Fri, 2 Aug 2013 07:59:02 +0200 Subject: [PATCH] systemd-delta: Only colorize output when on a tty --- src/delta/delta.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/delta/delta.c b/src/delta/delta.c index 49c2fc3..5ee754e 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -33,6 +33,8 @@ #include "build.h" #include "strv.h" +#define COLORIZE(color,msg) (on_tty()?color msg ANSI_HIGHLIGHT_OFF:msg) + static bool arg_no_pager = false; static int arg_diff = -1; @@ -66,7 +68,7 @@ static int notify_override_masked(const char *top, const char *bottom) { if (!(arg_flags & SHOW_MASKED)) return 0; - printf(ANSI_HIGHLIGHT_RED_ON "[MASKED]" ANSI_HIGHLIGHT_OFF " %s → %s\n", top, bottom); + printf("%s %s → %s\n", COLORIZE(ANSI_HIGHLIGHT_RED_ON,"[MASKED]"), top, bottom); return 1; } @@ -74,7 +76,7 @@ static int notify_override_equivalent(const char *top, const char *bottom) { if (!(arg_flags & SHOW_EQUIVALENT)) return 0; - printf(ANSI_HIGHLIGHT_GREEN_ON "[EQUIVALENT]" ANSI_HIGHLIGHT_OFF " %s → %s\n", top, bottom); + printf("%s %s → %s\n", COLORIZE(ANSI_HIGHLIGHT_GREEN_ON, "[EQUIVALENT]"), top, bottom); return 1; } @@ -82,7 +84,7 @@ static int notify_override_redirected(const char *top, const char *bottom) { if (!(arg_flags & SHOW_REDIRECTED)) return 0; - printf(ANSI_HIGHLIGHT_ON "[REDIRECTED]" ANSI_HIGHLIGHT_OFF " %s → %s\n", top, bottom); + printf("%s %s → %s\n", COLORIZE(ANSI_HIGHLIGHT_ON, "[REDIRECTED]"), top, bottom); return 1; } @@ -90,7 +92,7 @@ static int notify_override_overridden(const char *top, const char *bottom) { if (!(arg_flags & SHOW_OVERRIDDEN)) return 0; - printf(ANSI_HIGHLIGHT_ON "[OVERRIDDEN]" ANSI_HIGHLIGHT_OFF " %s → %s\n", top, bottom); + printf("%s %s → %s\n", COLORIZE(ANSI_HIGHLIGHT_ON, "[OVERRIDDEN]"), top, bottom); return 1; } @@ -98,7 +100,7 @@ static int notify_override_extended(const char *top, const char *bottom) { if (!(arg_flags & SHOW_EXTENDED)) return 0; - printf(ANSI_HIGHLIGHT_ON "[EXTENDED]" ANSI_HIGHLIGHT_OFF " %s → %s\n", top, bottom); + printf("%s %s → %s\n", COLORIZE(ANSI_HIGHLIGHT_ON, "[EXTENDED]"), top, bottom); return 1; } -- 1.8.4.rc0