commit:     c517951d98b6ae3c9ca0c838c029641287bd4d8d
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Feb 18 06:55:02 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Feb 19 16:14:06 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=c517951d

Support NO_COLOR as a means of suppressing coloured output

Per https://no-color.org/, NO_COLOR is a de-facto standard for allowing
the user to express their preference for not seeing coloured output.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 functions.sh | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/functions.sh b/functions.sh
index fbc0812..d068627 100644
--- a/functions.sh
+++ b/functions.sh
@@ -479,20 +479,23 @@ RC_GOT_FUNCTIONS="yes"
 EINFO_QUIET="${EINFO_QUIET:-no}"
 EINFO_VERBOSE="${EINFO_VERBOSE:-no}"
 
-# Should we use color?
-RC_NOCOLOR="${RC_NOCOLOR:-no}"
-
 # Set the initial value for e-message indentation.
 genfun_indent=
 
-for _ in "$@"; do
-       case $_ in
-               # Check whether the user specifed an argument to disable color.
-               --nocolor|--nocolour|-C)
-                       RC_NOCOLOR="yes"
-                       break
-       esac
-done
+# Should we use color?
+if [ -n "${NO_COLOR}" ]; then
+       # See https://no-color.org/.
+       RC_NOCOLOR="yes"
+else
+       RC_NOCOLOR="${RC_NOCOLOR:-no}"
+       for _ in "$@"; do
+               case $_ in
+                       --nocolor|--nocolour|-C)
+                               RC_NOCOLOR="yes"
+                               break
+               esac
+       done
+fi
 
 # Try to determine the number of available columns in the terminal.
 for _ in 1 2 3; do

Reply via email to