Add honor the NO_COLOR env var

This commit is contained in:
Christian W. Zuckschwerdt 2024-02-16 09:05:21 +01:00
parent f88bf68578
commit 5786c01c8c

View file

@ -228,13 +228,19 @@ int term_has_color(void *ctx)
#ifdef _WIN32 #ifdef _WIN32
return _term_has_color(ctx); return _term_has_color(ctx);
#else #else
char const *env = getenv("RTL433_COLOR"); char const *color = getenv("RTL433_COLOR");
if (env && strcmp(env, "always") == 0) { if (color && strcmp(color, "always") == 0) {
return 1; return 1;
} }
if (env && strcmp(env, "never") == 0) { if (color && strcmp(color, "never") == 0) {
return 0; return 0;
} }
char const *no_color = getenv("NO_COLOR");
if (no_color && no_color[0] != '\0') {
return 0;
}
FILE *fp = (FILE *)ctx; FILE *fp = (FILE *)ctx;
return isatty(fileno(fp)); return isatty(fileno(fp));
#endif #endif