commit: 1c801ce130726a81c59b96cdf4e2bef27893e0b7
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Thu Jul 28 00:57:17 2022 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Jul 29 02:03:03 2022 +0000
URL:
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=1c801ce1
functions.sh: fix TTY detection
The use of stdout as an argument in consoletype seems to be based
on a misunderstanding. It doesn't do anything except guarantee
the exit status is 0. The value is thrown away anyway.
This fixes e.g. elibtoolize (from elt-patches) having no colour
for its e.g. ewarn/einfo/etc because when invoked from an ebuild,
it's detected as serial.
Use a simpler test instead. We may want to clean up the logic
in consoletype in future too (just drop lines 82-85?).
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
functions.sh | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/functions.sh b/functions.sh
index 53cc189..be67536 100644
--- a/functions.sh
+++ b/functions.sh
@@ -404,13 +404,11 @@ RC_INDENTATION=''
RC_DEFAULT_INDENT=2
RC_DOT_PATTERN=''
-# Cache the CONSOLETYPE - this is important as backgrounded shells don't
-# have a TTY. rc unsets it at the end of running so it shouldn't hang
-# around
-if [ -z "${CONSOLETYPE}" ] ; then
- CONSOLETYPE="$(consoletype stdout 2>/dev/null )"; export CONSOLETYPE
-fi
-if [ "${CONSOLETYPE}" = "serial" ] ; then
+# If either STDOUT or STDERR is not a tty, disable coloured output. A useful
+# improvement for the future would be to have the individual logging functions
+# act as they should. For example, ewarn prints to STDOUT whereas eerror prints
+# to STDERR. For now, this is a reasonable compromise.
+if [ ! -t 1 ] || [ ! -t 2 ]; then
RC_NOCOLOR="yes"
RC_ENDCOL="no"
fi