summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerin Millar <kfm@plushkava.net>2022-07-28 01:57:17 +0100
committerSam James <sam@gentoo.org>2022-07-29 03:03:03 +0100
commit1c801ce130726a81c59b96cdf4e2bef27893e0b7 (patch)
tree7160ebb6499e69cfa83c2f6d2f948e05af21040b
parentSet VERSION = 0.15 (diff)
downloadgentoo-functions-1c801ce130726a81c59b96cdf4e2bef27893e0b7.tar.gz
gentoo-functions-1c801ce130726a81c59b96cdf4e2bef27893e0b7.tar.bz2
gentoo-functions-1c801ce130726a81c59b96cdf4e2bef27893e0b7.zip
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@plushkava.net> Signed-off-by: Sam James <sam@gentoo.org>
-rw-r--r--functions.sh12
1 files 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