add NO_COLOR support

This commit is contained in:
fatalerrors
2026-03-25 15:27:23 +01:00
parent d8bdfefdf1
commit 080511d0bd

View File

@@ -124,25 +124,45 @@ export On_IWhite='\e[0;107m'
# D : debug (cyan)
disp()
{
# Handle NO_COLOR: disable colors if set
local color_enabled=1
[[ -n $NO_COLOR ]] && color_enabled=0
case $1 in
"I")
local heads="[ ${IGreen}info${DEFAULTFG} ]"
if [[ $color_enabled -eq 1 ]]; then
local heads="[ ${IGreen}info${DEFAULTFG} ]"
else
local heads="[ info ]"
fi
shift
[[ -z $QUIET || $QUIET -ne 1 ]] && \
printf "%b\n" "${heads} $*${RESETCOL}"
;;
"W")
local heads="[ ${IYellow}Warning${DEFAULTFG} ]"
if [[ $color_enabled -eq 1 ]]; then
local heads="[ ${IYellow}Warning${DEFAULTFG} ]"
else
local heads="[ Warning ]"
fi
shift
printf "%b\n" "${heads} $*${RESETCOL}" >&2
;;
"E")
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
if [[ $color_enabled -eq 1 ]]; then
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
else
local heads="[ ERROR ]"
fi
shift
printf "%b\n" "${heads} $*${RESETCOL}" >&2
;;
"D")
local heads="[ ${ICyan}debug${DEFAULTFG} ]"
if [[ $color_enabled -eq 1 ]]; then
local heads="[ ${ICyan}debug${DEFAULTFG} ]"
else
local heads="[ debug ]"
fi
shift
[[ -n $DEBUG && $DEBUG -gt 1 ]] && \
printf "%b\n" "${heads} $*${RESETCOL}"
@@ -157,4 +177,7 @@ export -f disp
# ------------------------------------------------------------------------------
# Load disp section variables
load_conf disp
# EOF