summaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
authorLyndon Brown <jnqnfe@gmail.com>2020-03-13 18:36:26 +0000
committerRaphaƫl Hertzog <hertzog@debian.org>2020-03-16 13:32:16 +0000
commitca520eb5f0556094338e0c841dcaa970d9a28886 (patch)
tree10ebfc87bda84f81e7a4c285054d607b651d28ab /functions
parent09b279b7bc02c5aeec3fc5e75732b338f92a3921 (diff)
downloadvyos-live-build-ca520eb5f0556094338e0c841dcaa970d9a28886.tar.gz
vyos-live-build-ca520eb5f0556094338e0c841dcaa970d9a28886.zip
split stdout & stderr auto colouring
thus for some reason if one is connected to a tty and the other a file, we still get colour in the tty by default. in terms of options, --color and --no-color override both, no granular ones added since it's not worth it imo. this is backwards compatible with custom configs setting `_COLOR`. it could be argued that setting $_COLOR to "false" for the auto non-tty cases is redundant, which it is, but it doesn't hurt to do so; it ensures that if anything (inc. 3rd-party hooks and such) rely on it that it remains correct; and ensures that if anything in the future mistakenly uses $_COLOR instead of $_COLOR_OUT|$_COLOR_ERR that at least that will only be broken for the use case of only one of stdout|sdterr being a tty. Gbp-Dch: Ignore
Diffstat (limited to 'functions')
-rwxr-xr-xfunctions/arguments.sh4
-rwxr-xr-xfunctions/defaults.sh15
-rwxr-xr-xfunctions/echo.sh6
3 files changed, 19 insertions, 6 deletions
diff --git a/functions/arguments.sh b/functions/arguments.sh
index 877a24dd8..5d406f4b5 100755
--- a/functions/arguments.sh
+++ b/functions/arguments.sh
@@ -34,11 +34,15 @@ Arguments ()
--color)
_COLOR="true"
+ _COLOR_OUT="true"
+ _COLOR_ERR="true"
shift
;;
--no-color)
_COLOR="false"
+ _COLOR_OUT="false"
+ _COLOR_ERR="false"
shift
;;
diff --git a/functions/defaults.sh b/functions/defaults.sh
index 108a9d96e..786a9dc4c 100755
--- a/functions/defaults.sh
+++ b/functions/defaults.sh
@@ -296,10 +296,19 @@ Set_config_defaults ()
esac
# Setting live build options
- if [ -t 1 ] && [ -t 2 ]; then
- _COLOR="${_COLOR:-true}"
+ if [ -z "${_COLOR}" ]; then
+ _COLOR="auto"
+ _COLOR_OUT="true"
+ _COLOR_ERR="true"
+ if [ ! -t 1 ]; then
+ _COLOR_OUT="false"
+ fi
+ if [ ! -t 2 ]; then
+ _COLOR_ERR="false"
+ fi
else
- _COLOR="${_COLOR:-false}"
+ _COLOR_OUT="${_COLOR}"
+ _COLOR_ERR="${_COLOR}"
fi
_BREAKPOINTS="${_BREAKPOINTS:-false}"
_DEBUG="${_DEBUG:-false}"
diff --git a/functions/echo.sh b/functions/echo.sh
index af3c4ca56..e019d8ed7 100755
--- a/functions/echo.sh
+++ b/functions/echo.sh
@@ -34,7 +34,7 @@ Echo_error ()
shift
local PREFIX="${RED}E${NO_COLOR}"
- if [ "${_COLOR}" = "false" ]; then
+ if [ "${_COLOR_ERR}" = "false" ]; then
PREFIX="E"
fi
@@ -49,7 +49,7 @@ Echo_message ()
shift
local PREFIX="${PURPLE}P${NO_COLOR}"
- if [ "${_COLOR}" = "false" ]; then
+ if [ "${_COLOR_OUT}" = "false" ]; then
PREFIX="P"
fi
@@ -73,7 +73,7 @@ Echo_warning ()
shift
local PREFIX="${YELLOW}W${NO_COLOR}"
- if [ "${_COLOR}" = "false" ]; then
+ if [ "${_COLOR_ERR}" = "false" ]; then
PREFIX="W"
fi