From 29a09faf165626513584e4b435b92104fa0bf62c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stig-=C3=98rjan=20Smelror?= Date: Wed, 14 Feb 2024 17:56:21 +0100 Subject: [PATCH] _msg: Refactor to enable escaped commands --- qsgen2 | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/qsgen2 b/qsgen2 index f4acd2a..e909009 100755 --- a/qsgen2 +++ b/qsgen2 @@ -77,39 +77,25 @@ function _msg() { local full_msg="" for arg in "$@"; do if [[ -n "${qsgenlang[$arg]}" ]]; then - # echo "Found key: $arg" # Debug line to confirm key is found full_msg+="${qsgenlang[$arg]}" else - # echo "Key not found: $arg" # Debug line for keys not found full_msg+="$arg" fi 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 - std) - printf "${green}%s${end}\n" "${full_msg}" - ;; - info) - printf "${yellow}%s${end}\n" "${full_msg}" - ;; - 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}" - ;; + std) color="${green}" ;; + info) color="${yellow}" ;; + debug) color="${red}" ;; + other) color="${bold_yellow}" ;; + sub) color="${magenta}" ;; + main) color="${white}${green_bg}" ;; esac + # Use printf with %b to allow backslash escape interpretation + printf "${color}%b${end}\n" "${full_msg}" } function _version() {