mirror of
https://github.com/kvz/bash3boilerplate.git
synced 2025-03-01 01:46:09 +00:00
Merge pull request #70 from mstreuhofer/color
Fix auto-color-off code Thanks to @mstreuhofer for another great contribution 🎊 🙇
This commit is contained in:
commit
68323978d4
24
main.sh
24
main.sh
@ -75,9 +75,11 @@ 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
|
||||||
# Don't use colors on pipes or non-recognized terminals
|
if [ "${NO_COLOR:-}" != "false" ]; then
|
||||||
color=""; color_reset=""
|
# Don't use colors on pipes or non-recognized terminals
|
||||||
|
color=""; color_reset=""
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# all remaining arguments are to be printed
|
# all remaining arguments are to be printed
|
||||||
@ -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
|
||||||
|
@ -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.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user