From 38ad1c5824130a4189ca187f759c67d43ace820c Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 13 Sep 2015 10:57:51 +0200 Subject: [PATCH] Disable color output if stdout is not a terminal Don't color output if it's redirected to a pipe or a file. Signed-off-by: Sebastien GODARD --- common.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common.c b/common.c index e6af880..c3034e1 100644 --- a/common.c +++ b/common.c @@ -936,8 +936,11 @@ char *get_pretty_name_from_persistent(char *persistent) void init_colors(void) { /* Read environment variable value */ - if (getenv(ENV_COLORS) == NULL) { - /* Environment variable not set: Unset color strings */ + if (!getenv(ENV_COLORS) || !isatty(STDOUT_FILENO)) { + /* + * Environment variable is not set or stdout is not a terminal: + * Unset color strings. + */ strcpy(sc_percent_high, ""); strcpy(sc_percent_low, ""); strcpy(sc_zero_int_stat, ""); -- 2.40.0