From 9c440c027913a7e8f1a417bd93d98628e8f85df4 Mon Sep 17 00:00:00 2001 From: lemon Date: Sun, 28 May 2023 09:59:54 +0200 Subject: check color output --- main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 8f72dd9..2404fd5 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,7 @@ #include "common.h" #include "parse.h" #include +#include struct option ccopt; @@ -42,6 +43,16 @@ optparse(const char **file, const char **targ, char **args) } } +static void +detectcolor(void) +{ + const char *s; + if (!isatty(STDERR_FILENO) + || ((s = getenv("NO_COLOR")) && *s) + || ((s = getenv("TERM")) && !strcmp(s, "dumb"))) + ccopt.nocolor = 1; +} + int main(int argc, char **argv) { @@ -49,6 +60,7 @@ main(int argc, char **argv) const char *file, *targ; atexit(flushstd); + detectcolor(); optparse(&file, &targ, argv); if (!file) { efmt("usage: %s [options] \n", *argv); -- cgit v1.2.3