summaryrefslogtreecommitdiffstats
path: root/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2019-04-27 11:45:59 -0400
committerTavian Barnes <tavianator@tavianator.com>2019-04-27 11:45:59 -0400
commitcf32dc8b4fd4d56b14e43aacdb0f08aecaa19f6d (patch)
tree8981bdc507d4a0a2a8c5fa453358b063a516de17 /parse.c
parentc2fb81bf1668e3c69df7d533c32a580742d709ab (diff)
downloadbfs-cf32dc8b4fd4d56b14e43aacdb0f08aecaa19f6d.tar.xz
Add support for the NO_COLOR environment variable
C.f. https://no-color.org/
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/parse.c b/parse.c
index 2eb7eca..6367cd6 100644
--- a/parse.c
+++ b/parse.c
@@ -3162,9 +3162,15 @@ struct cmdline *parse_cmdline(int argc, char *argv[]) {
cmdline->argv[i] = argv[i];
}
+ enum use_color use_color = COLOR_AUTO;
+ if (getenv("NO_COLOR")) {
+ // https://no-color.org/
+ use_color = COLOR_NEVER;
+ }
+
cmdline->colors = parse_colors(getenv("LS_COLORS"));
- cmdline->cout = cfdup(stdout, cmdline->colors);
- cmdline->cerr = cfdup(stderr, cmdline->colors);
+ cmdline->cout = cfdup(stdout, use_color ? cmdline->colors : NULL);
+ cmdline->cerr = cfdup(stderr, use_color ? cmdline->colors : NULL);
if (!cmdline->cout || !cmdline->cerr) {
perror("cfdup()");
goto fail;
@@ -3175,7 +3181,7 @@ struct cmdline *parse_cmdline(int argc, char *argv[]) {
cmdline->mtab_error = errno;
}
- bool stderr_tty = cmdline->cerr->colors;
+ bool stderr_tty = isatty(STDERR_FILENO);
bool stdin_tty = isatty(STDIN_FILENO);
struct parser_state state = {
@@ -3185,7 +3191,7 @@ struct cmdline *parse_cmdline(int argc, char *argv[]) {
.roots_tail = &cmdline->roots,
.regex_flags = 0,
.interactive = stderr_tty && stdin_tty,
- .use_color = COLOR_AUTO,
+ .use_color = use_color,
.implicit_print = true,
.warn = stdin_tty,
.non_option_seen = false,