🚑 Brings sanity to color output

This commit is contained in:
Franck Nijhof 2019-03-15 22:27:43 +01:00
parent 01c49dcea6
commit 9ba69c749b
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
2 changed files with 107 additions and 35 deletions

View file

@ -11,124 +11,124 @@
# Reset color output (background and foreground colors). # Reset color output (background and foreground colors).
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.reset() { function bashio::color.reset() {
printf "${__BASHIO_COLORS_RESET}" >&2 echo -n -e "${__BASHIO_COLORS_RESET}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set default output color. # Set default output color.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.default() { function bashio::color.default() {
printf "${__BASHIO_COLORS_DEFAULT}" >&2 echo -n -e "${__BASHIO_COLORS_DEFAULT}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color to black. # Set font output color to black.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.black() { function bashio::color.black() {
printf "${__BASHIO_COLORS_BLACK}" >&2 echo -n -e "${__BASHIO_COLORS_BLACK}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color to red. # Set font output color to red.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.red() { function bashio::color.red() {
printf "${__BASHIO_COLORS_RED}" >&2 echo -n -e "${__BASHIO_COLORS_RED}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color to green. # Set font output color to green.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.green() { function bashio::color.green() {
printf "${__BASHIO_COLORS_GREEN}" >&2 echo -n -e "${__BASHIO_COLORS_GREEN}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color to yellow. # Set font output color to yellow.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.yellow() { function bashio::color.yellow() {
printf "${__BASHIO_COLORS_YELLOW}" >&2 echo -n -e "${__BASHIO_COLORS_YELLOW}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color to blue. # Set font output color to blue.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.blue() { function bashio::color.blue() {
printf "${__BASHIO_COLORS_BLUE}" >&2 echo -n -e "${__BASHIO_COLORS_BLUE}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color to magenta. # Set font output color to magenta.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.magenta() { function bashio::color.magenta() {
printf "${__BASHIO_COLORS_MAGENTA}" >&2 echo -n -e "${__BASHIO_COLORS_MAGENTA}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color to cyan. # Set font output color to cyan.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.cyan() { function bashio::color.cyan() {
printf "${__BASHIO_COLORS_CYAN}" >&2 echo -n -e "${__BASHIO_COLORS_CYAN}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color background to default. # Set font output color background to default.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.bg.default() { function bashio::color.bg.default() {
printf "${__BASHIO_COLORS_BG_DEFAULT}" >&2 echo -n -e "${__BASHIO_COLORS_BG_DEFAULT}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color background to black. # Set font output color background to black.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.bg.black() { function bashio::color.bg.black() {
printf "${__BASHIO_COLORS_BG_BLACK}" >&2 echo -n -e "${__BASHIO_COLORS_BG_BLACK}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color background to red. # Set font output color background to red.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.bg.red() { function bashio::color.bg.red() {
printf "${__BASHIO_COLORS_BG_RED}" >&2 echo -n -e "${__BASHIO_COLORS_BG_RED}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color background to green. # Set font output color background to green.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.bg.green() { function bashio::color.bg.green() {
printf "${__BASHIO_COLORS_BG_GREEN}" >&2 echo -n -e "${__BASHIO_COLORS_BG_GREEN}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color background to yellow. # Set font output color background to yellow.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.bg.yellow() { function bashio::color.bg.yellow() {
printf "${__BASHIO_COLORS_BG_YELLOW}" >&2 echo -n -e "${__BASHIO_COLORS_BG_YELLOW}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color background to blue. # Set font output color background to blue.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.bg.blue() { function bashio::color.bg.blue() {
printf "${__BASHIO_COLORS_BG_BLUE}" >&2 echo -n -e "${__BASHIO_COLORS_BG_BLUE}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color background to magenta. # Set font output color background to magenta.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.bg.magenta() { function bashio::color.bg.magenta() {
printf "${__BASHIO_COLORS_BG_MAGENTA}" >&2 echo -n -e "${__BASHIO_COLORS_BG_MAGENTA}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color background to cyan. # Set font output color background to cyan.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.bg.cyan() { function bashio::color.bg.cyan() {
printf "${__BASHIO_COLORS_BG_CYAN}" >&2 echo -n -e "${__BASHIO_COLORS_BG_CYAN}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Set font output color background to white. # Set font output color background to white.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::color.bg.white() { function bashio::color.bg.white() {
printf "${__BASHIO_COLORS_BG_WHITE}" >&2 echo -n -e "${__BASHIO_COLORS_BG_WHITE}"
} }

View file

@ -15,7 +15,79 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
bashio::log() { bashio::log() {
local message=${1} local message=${1}
echo "${message}" >&2 echo -e "${message}" >&2
return "${__BASHIO_EXIT_OK}"
}
# ------------------------------------------------------------------------------
# Log a message to output (in red).
#
# Arguments:
# $1 Message to display
# ------------------------------------------------------------------------------
bashio::log.red() {
local message=${1}
echo -e "${__BASHIO_COLORS_RED}${message}${__BASHIO_COLORS_RESET}" >&2
return "${__BASHIO_EXIT_OK}"
}
# ------------------------------------------------------------------------------
# Log a message to output (in green).
#
# Arguments:
# $1 Message to display
# ------------------------------------------------------------------------------
bashio::log.green() {
local message=${1}
echo -e "${__BASHIO_COLORS_GREEN}${message}${__BASHIO_COLORS_RESET}" >&2
return "${__BASHIO_EXIT_OK}"
}
# ------------------------------------------------------------------------------
# Log a message to output (in yellow).
#
# Arguments:
# $1 Message to display
# ------------------------------------------------------------------------------
bashio::log.yellow() {
local message=${1}
echo -e "${__BASHIO_COLORS_YELLOW}${message}${__BASHIO_COLORS_RESET}" >&2
return "${__BASHIO_EXIT_OK}"
}
# ------------------------------------------------------------------------------
# Log a message to output (in blue).
#
# Arguments:
# $1 Message to display
# ------------------------------------------------------------------------------
bashio::log.blue() {
local message=${1}
echo -e "${__BASHIO_COLORS_BLUE}${message}${__BASHIO_COLORS_RESET}" >&2
return "${__BASHIO_EXIT_OK}"
}
# ------------------------------------------------------------------------------
# Log a message to output (in magenta).
#
# Arguments:
# $1 Message to display
# ------------------------------------------------------------------------------
bashio::log.magenta() {
local message=${1}
echo -e "${__BASHIO_COLORS_MAGENTA}${message}${__BASHIO_COLORS_RESET}" >&2
return "${__BASHIO_EXIT_OK}"
}
# ------------------------------------------------------------------------------
# Log a message to output (in cyan).
#
# Arguments:
# $1 Message to display
# ------------------------------------------------------------------------------
bashio::log.cyan() {
local message=${1}
echo -e "${__BASHIO_COLORS_CYAN}${message}${__BASHIO_COLORS_RESET}" >&2
return "${__BASHIO_EXIT_OK}" return "${__BASHIO_EXIT_OK}"
} }
@ -43,7 +115,7 @@ function bashio::log.log() {
output="${output//\{MESSAGE\}/${message}}" output="${output//\{MESSAGE\}/${message}}"
output="${output//\{LEVEL\}/${__BASHIO_LOG_LEVELS[$level]}}" output="${output//\{LEVEL\}/${__BASHIO_LOG_LEVELS[$level]}}"
echo "${output}" >&2 echo -e "${output}" >&2
return "${__BASHIO_EXIT_OK}" return "${__BASHIO_EXIT_OK}"
} }
@ -78,9 +150,9 @@ function bashio::log.debug() {
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::log.info() { function bashio::log.info() {
local message=$* local message=$*
bashio::color.cyan bashio::log.log \
bashio::log.log "${__BASHIO_LOG_LEVEL_INFO}" "${message}" "${__BASHIO_LOG_LEVEL_INFO}" \
bashio::color.reset "${__BASHIO_COLORS_BLUE}${message}${__BASHIO_COLORS_RESET}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -91,9 +163,9 @@ function bashio::log.info() {
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::log.notice() { function bashio::log.notice() {
local message=$* local message=$*
bashio::color.blue bashio::log.log \
bashio::log.log "${__BASHIO_LOG_LEVEL_NOTICE}" "${message}" "${__BASHIO_LOG_LEVEL_NOTICE}" \
bashio::color.reset "${__BASHIO_COLORS_CYAN}${message}${__BASHIO_COLORS_RESET}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -104,9 +176,9 @@ function bashio::log.notice() {
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::log.warning() { function bashio::log.warning() {
local message=$* local message=$*
bashio::color.yellow bashio::log.log \
bashio::log.log "${__BASHIO_LOG_LEVEL_WARNING}" "${message}" "${__BASHIO_LOG_LEVEL_WARNING}" \
bashio::color.reset "${__BASHIO_COLORS_YELLOW}${message}${__BASHIO_COLORS_RESET}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -117,9 +189,9 @@ function bashio::log.warning() {
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::log.error() { function bashio::log.error() {
local message=$* local message=$*
bashio::color.magenta bashio::log.log \
bashio::log.log "${__BASHIO_LOG_LEVEL_ERROR}" "${message}" "${__BASHIO_LOG_LEVEL_ERROR}" \
bashio::color.reset "${__BASHIO_COLORS_MAGENTA}${message}${__BASHIO_COLORS_RESET}"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
@ -130,7 +202,7 @@ function bashio::log.error() {
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function bashio::log.fatal() { function bashio::log.fatal() {
local message=$* local message=$*
bashio::color.red bashio::log.log \
bashio::log.log "${__BASHIO_LOG_LEVEL_FATAL}" "${message}" "${__BASHIO_LOG_LEVEL_FATAL}" \
bashio::color.reset "${__BASHIO_COLORS_RED}${message}${__BASHIO_COLORS_RESET}"
} }