2017-05-14 20:35:13 +02:00
|
|
|
# The check for terminal output and color support is heavily inspired
|
|
|
|
# by https://unix.stackexchange.com/a/10065.
|
2021-03-01 13:22:33 +01:00
|
|
|
#
|
|
|
|
# Allow opt out by respecting the `NO_COLOR` environment variable.
|
2017-05-14 20:35:13 +02:00
|
|
|
|
2017-05-14 16:17:38 +02:00
|
|
|
function setupColors() {
|
|
|
|
normalColor=""
|
|
|
|
errorColor=""
|
|
|
|
warnColor=""
|
|
|
|
noteColor=""
|
|
|
|
|
2021-03-01 13:22:33 +01:00
|
|
|
# Enable colors for terminals, and allow opting out.
|
|
|
|
if [[ ! -v NO_COLOR && -t 1 ]]; then
|
2017-05-14 16:17:38 +02:00
|
|
|
# See if it supports colors.
|
|
|
|
local ncolors
|
|
|
|
ncolors=$(tput colors)
|
|
|
|
|
|
|
|
if [[ -n "$ncolors" && "$ncolors" -ge 8 ]]; then
|
|
|
|
normalColor="$(tput sgr0)"
|
|
|
|
errorColor="$(tput bold)$(tput setaf 1)"
|
|
|
|
warnColor="$(tput setaf 3)"
|
|
|
|
noteColor="$(tput bold)$(tput setaf 6)"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
setupColors
|
|
|
|
|
|
|
|
function errorEcho() {
|
|
|
|
echo "${errorColor}$*${normalColor}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function warnEcho() {
|
|
|
|
echo "${warnColor}$*${normalColor}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function noteEcho() {
|
|
|
|
echo "${noteColor}$*${normalColor}"
|
|
|
|
}
|