From 3b9cbbe848bf8d8e968f2f244e0f750277fa8a23 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 27 Sep 2015 15:54:10 +0200 Subject: [PATCH] Define S_COLORS possible values Sysstat now takes into account the following values for S_COLOR environment variable: "never": Don't use colorization "always": Always use colorization "auto" (or any other value different from "never" and "always"): Use colorization only if stdout is a terminal. Signed-off-by: Sebastien GODARD --- common.c | 32 ++++++++++++++++++++------------ common.h | 3 +++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/common.c b/common.c index 81e9dab..aae31df 100644 --- a/common.c +++ b/common.c @@ -938,21 +938,29 @@ char *get_pretty_name_from_persistent(char *persistent) */ void init_colors(void) { + char *e; + /* Read environment variable value */ - if (!getenv(ENV_COLORS) || !isatty(STDOUT_FILENO)) { + if (((e = getenv(ENV_COLORS)) != NULL) && !strcmp(e, C_ALWAYS)) + /* Variable set to "always" */ + return; + + if (e && strcmp(e, C_NEVER) && isatty(STDOUT_FILENO)) /* - * Environment variable is not set or stdout is not a terminal: - * Unset color strings. + * Variable set to "auto" (or any other value different + * from "never") and stdout is a terminal. */ - strcpy(sc_percent_high, ""); - strcpy(sc_percent_low, ""); - strcpy(sc_zero_int_stat, ""); - strcpy(sc_int_stat, ""); - strcpy(sc_item_name, ""); - strcpy(sc_sa_comment, ""); - strcpy(sc_sa_restart, ""); - strcpy(sc_normal, ""); - } + return; + + /* Other cases: Unset color strings */ + strcpy(sc_percent_high, ""); + strcpy(sc_percent_low, ""); + strcpy(sc_zero_int_stat, ""); + strcpy(sc_int_stat, ""); + strcpy(sc_item_name, ""); + strcpy(sc_sa_comment, ""); + strcpy(sc_sa_restart, ""); + strcpy(sc_normal, ""); } /* diff --git a/common.h b/common.h index b49b622..aa282b6 100644 --- a/common.h +++ b/common.h @@ -86,6 +86,9 @@ #define ENV_TIME_DEFTM "S_TIME_DEF_TIME" #define ENV_COLORS "S_COLORS" +#define C_NEVER "never" +#define C_ALWAYS "always" + #define DIGITS "0123456789" /* -- 2.40.0