Bruno Haible 7040b13946 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.
2019-08-14 02:46:36 +02:00
..