Merge pull request #70 from mstreuhofer/color

Fix auto-color-off code

 Thanks to @mstreuhofer for another great contribution 🎊 🙇
This commit is contained in:
Izaak Beekman 2016-12-05 12:37:28 -05:00 committed by GitHub
commit 68323978d4
2 changed files with 18 additions and 11 deletions

20
main.sh
View File

@ -75,10 +75,12 @@ function __b3bp_log () {
local color="${!colorvar:-$color_error}" local color="${!colorvar:-$color_error}"
local color_reset="\x1b[0m" local color_reset="\x1b[0m"
if [ "${NO_COLOR}" = "true" ] || [[ "${TERM:-}" != "xterm"* ]] || [ -t 1 ]; then if [ "${NO_COLOR:-}" = "true" ] || [[ "${TERM:-}" != "xterm"* ]] || [ ! -t 2 ]; then
if [ "${NO_COLOR:-}" != "false" ]; then
# Don't use colors on pipes or non-recognized terminals # Don't use colors on pipes or non-recognized terminals
color=""; color_reset="" color=""; color_reset=""
fi fi
fi
# all remaining arguments are to be printed # all remaining arguments are to be printed
local log_line="" local log_line=""
@ -88,14 +90,14 @@ function __b3bp_log () {
done <<< "${@:-}" done <<< "${@:-}"
} }
function emergency () { $(__b3bp_log emergency "${@}"); exit 1; } function emergency () { __b3bp_log emergency "${@}"; exit 1; }
function alert () { [ "${LOG_LEVEL:-0}" -ge 1 ] && $(__b3bp_log alert "${@}"); true; } function alert () { [ "${LOG_LEVEL:-0}" -ge 1 ] && __b3bp_log alert "${@}"; true; }
function critical () { [ "${LOG_LEVEL:-0}" -ge 2 ] && $(__b3bp_log critical "${@}"); true; } function critical () { [ "${LOG_LEVEL:-0}" -ge 2 ] && __b3bp_log critical "${@}"; true; }
function error () { [ "${LOG_LEVEL:-0}" -ge 3 ] && $(__b3bp_log error "${@}"); true; } function error () { [ "${LOG_LEVEL:-0}" -ge 3 ] && __b3bp_log error "${@}"; true; }
function warning () { [ "${LOG_LEVEL:-0}" -ge 4 ] && $(__b3bp_log warning "${@}"); true; } function warning () { [ "${LOG_LEVEL:-0}" -ge 4 ] && __b3bp_log warning "${@}"; true; }
function notice () { [ "${LOG_LEVEL:-0}" -ge 5 ] && $(__b3bp_log notice "${@}"); true; } function notice () { [ "${LOG_LEVEL:-0}" -ge 5 ] && __b3bp_log notice "${@}"; true; }
function info () { [ "${LOG_LEVEL:-0}" -ge 6 ] && $(__b3bp_log info "${@}"); true; } function info () { [ "${LOG_LEVEL:-0}" -ge 6 ] && __b3bp_log info "${@}"; true; }
function debug () { [ "${LOG_LEVEL:-0}" -ge 7 ] && $(__b3bp_log debug "${@}"); true; } function debug () { [ "${LOG_LEVEL:-0}" -ge 7 ] && __b3bp_log debug "${@}"; true; }
function help () { function help () {
echo "" 1>&2 echo "" 1>&2

View File

@ -62,6 +62,11 @@ if ! which "${cmdSed}" > /dev/null; then
exit 1 exit 1
fi fi
# explicitly setting NO_COLOR to false will make b3bp ignore TERM
# not being "xterm*" and STDERR not being connected to a terminal
# it's the opposite of NO_COLOR="true" - it forces color, no matter what
export NO_COLOR="false"
# Running prepare before other scenarios is important on Travis, # Running prepare before other scenarios is important on Travis,
# so that stdio can diverge - and we can enforce stricter # so that stdio can diverge - and we can enforce stricter
# stdio comparison on all other tests. # stdio comparison on all other tests.