_msg: Refactor to enable escaped commands

This commit is contained in:
Stig-Ørjan Smelror 2024-02-14 17:56:21 +01:00
parent 7805e4a89b
commit 29a09faf16

34
qsgen2
View File

@ -77,39 +77,25 @@ function _msg() {
local full_msg="" local full_msg=""
for arg in "$@"; do for arg in "$@"; do
if [[ -n "${qsgenlang[$arg]}" ]]; then if [[ -n "${qsgenlang[$arg]}" ]]; then
# echo "Found key: $arg" # Debug line to confirm key is found
full_msg+="${qsgenlang[$arg]}" full_msg+="${qsgenlang[$arg]}"
else else
# echo "Key not found: $arg" # Debug line for keys not found
full_msg+="$arg" full_msg+="$arg"
fi fi
done done
# Apply color formatting based on type and use printf for safe output # Determine the color based on the type
local color="${end}" # Default to no color if type is unrecognized
case $type in case $type in
std) std) color="${green}" ;;
printf "${green}%s${end}\n" "${full_msg}" info) color="${yellow}" ;;
;; debug) color="${red}" ;;
info) other) color="${bold_yellow}" ;;
printf "${yellow}%s${end}\n" "${full_msg}" sub) color="${magenta}" ;;
;; main) color="${white}${green_bg}" ;;
debug)
printf "${red}%s${end}\n" "${full_msg}"
;;
other)
printf "${bold_yellow}%s${end}\n" "${full_msg}"
;;
sub)
printf "${magenta}%s${end}\n" "${full_msg}"
;;
main)
printf "${white}${green_bg} %s ${end}\n" "${full_msg}"
;;
*)
printf "%s\n" "${full_msg}"
;;
esac esac
# Use printf with %b to allow backslash escape interpretation
printf "${color}%b${end}\n" "${full_msg}"
} }
function _version() { function _version() {