diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-11-06 13:08:56 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-11-06 13:08:56 -0500 |
commit | 79aee58a4621d01c4b1e98c332775f3b87213ddb (patch) | |
tree | ebaa28d4abd07e7957b17e3dfcdf7ae33e3792c7 | |
parent | 7d69fef6a0b80ad57acde7bac8a22b83531fec0d (diff) | |
download | bfs-79aee58a4621d01c4b1e98c332775f3b87213ddb.tar.xz |
Treat NO_COLOR="" the same as unset
The docs say
> Command-line software which adds ANSI color to its output by default
> should check for a NO_COLOR environment variable that, when present
> and not an empty string (regardless of its value), prevents the
> addition of ANSI color.
but we were not checking for the empty string.
Link: https://no-color.org/
Link: https://github.com/sharkdp/fd/pull/1421
-rw-r--r-- | src/parse.c | 3 | ||||
-rw-r--r-- | tests/bfs/nocolor_env_empty.out | 27 | ||||
-rw-r--r-- | tests/bfs/nocolor_env_empty.sh | 5 |
3 files changed, 34 insertions, 1 deletions
diff --git a/src/parse.c b/src/parse.c index 3f32021..09cfdd3 100644 --- a/src/parse.c +++ b/src/parse.c @@ -3670,7 +3670,8 @@ struct bfs_ctx *bfs_parse_cmdline(int argc, char *argv[]) { } enum use_color use_color = COLOR_AUTO; - if (getenv("NO_COLOR")) { + const char *no_color = getenv("NO_COLOR"); + if (no_color && *no_color) { // https://no-color.org/ use_color = COLOR_NEVER; } diff --git a/tests/bfs/nocolor_env_empty.out b/tests/bfs/nocolor_env_empty.out new file mode 100644 index 0000000..a439814 --- /dev/null +++ b/tests/bfs/nocolor_env_empty.out @@ -0,0 +1,27 @@ +[01;34m$'rainbow/\e[1m'[0m +[01;34m$'rainbow/\e[1m/'[0m$'\e[0m' +[01;34mrainbow[0m +[01;34mrainbow/[0m[01;32mexec.sh[0m +[01;34mrainbow/[0m[01;35msocket[0m +[01;34mrainbow/[0m[01;36mbroken[0m +[01;34mrainbow/[0m[01;36mchardev_link[0m +[01;34mrainbow/[0m[01;36mlink.txt[0m +[01;34mrainbow/[0m[30;42msticky_ow[0m +[01;34mrainbow/[0m[30;43msgid[0m +[01;34mrainbow/[0m[33mpipe[0m +[01;34mrainbow/[0m[34;42mow[0m +[01;34mrainbow/[0m[37;41msugid[0m +[01;34mrainbow/[0m[37;41msuid[0m +[01;34mrainbow/[0m[37;44msticky[0m +[01;34mrainbow/[0mfile.dat +[01;34mrainbow/[0mfile.txt +[01;34mrainbow/[0mlower.gz +[01;34mrainbow/[0mlower.tar +[01;34mrainbow/[0mlower.tar.gz +[01;34mrainbow/[0mlu.tar.GZ +[01;34mrainbow/[0mmh1 +[01;34mrainbow/[0mmh2 +[01;34mrainbow/[0mul.TAR.gz +[01;34mrainbow/[0mupper.GZ +[01;34mrainbow/[0mupper.TAR +[01;34mrainbow/[0mupper.TAR.GZ diff --git a/tests/bfs/nocolor_env_empty.sh b/tests/bfs/nocolor_env_empty.sh new file mode 100644 index 0000000..0ffc046 --- /dev/null +++ b/tests/bfs/nocolor_env_empty.sh @@ -0,0 +1,5 @@ +command -v unbuffer &>/dev/null || skip + +NO_COLOR= bfs_pty rainbow >"$OUT" +sort_output +diff_output |