diff options
| author | 2023-05-28 09:59:54 +0200 | |
|---|---|---|
| committer | 2023-05-28 10:14:21 +0200 | |
| commit | 9c440c027913a7e8f1a417bd93d98628e8f85df4 (patch) | |
| tree | ad52c830805fee76427122b5e640e47d6f3c3ec5 /main.c | |
| parent | 6f7bea0cff2ecbca3427def8ead2c9ceec966b14 (diff) | |
check color output
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -1,6 +1,7 @@ #include "common.h" #include "parse.h" #include <stdlib.h> +#include <unistd.h> 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] <file>\n", *argv); |