]> git.ipfire.org Git - thirdparty/gettext.git/commit
libtextstyle: Support the NO_COLOR environment variable.
authorBruno Haible <bruno@clisp.org>
Wed, 14 Aug 2019 00:46:36 +0000 (02:46 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 14 Aug 2019 00:46:36 +0000 (02:46 +0200)
commit7040b13946b3dce5fbe2be8ecfda11e03eed7028
tree4fd8781f35b44732b3913ed5f4187ecc9bc3e9d7
parent8e280e2efdcb9fa9a5e93edb89354496a55f228a
libtextstyle: Support the NO_COLOR environment variable.

It follows the specification at https://no-color.org/.

The support is in the example programs, not in the function
styled_ostream_create, so that it can be overridden through the command-line
option --color=always.

We only test whether the environment variable is set, not whether its value
is non-empty. POSIX-specified environment variables are treated like unset
when their value is empty; this is because in the old days it was not possible
to unset an environment variable. But nowadays:
  - all shells support the 'unset' built-in,
  - all platforms that have the setenv() function also have the unsetenv()
    function, and
  - the 'env' program from GNU coreutils supports --unset=VARIABLE to unset a
    variable.
This makes it possible to unset an environment variable that is set by the
parent process.

* libtextstyle/adhoc-tests/hello.c (main): Do not emit styling when the
environment variable NO_COLOR is set.
* libtextstyle/examples/color-filter/filter.c (main): Likewise.
* libtextstyle/examples/color-hello/hello.c (main): Likewise.
* gettext-tools/src/write-catalog.c (msgdomain_list_print): Likewise.
* libtextstyle/doc/libtextstyle.texi (The NO_COLOR variable): New section.
* libtextstyle/NEWS: Mention it.
gettext-tools/src/write-catalog.c
libtextstyle/NEWS
libtextstyle/adhoc-tests/hello.c
libtextstyle/doc/libtextstyle.texi
libtextstyle/examples/color-filter/filter.c
libtextstyle/examples/color-hello/hello.c