From: hayao Date: Fri, 9 Oct 2020 12:15:50 +0000 (+0900) Subject: [update] : Added --labelcolor X-Git-Tag: rc3-alpha1~126^2~1 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=84fee3c73f9bb16d198ec2b0ac65507efa864934;p=alterlinux%2Falterlinux.git [update] : Added --labelcolor --- diff --git a/tools/msg.sh b/tools/msg.sh index 1ee4949e..5f959e16 100755 --- a/tools/msg.sh +++ b/tools/msg.sh @@ -14,6 +14,7 @@ msg_label="" label_space="7" adjust_chr=" " customized_label=false +customized_label_color=false nolabel=false noappname=false noadjust=false @@ -40,17 +41,23 @@ _help() { echo " -x | --bash-debug Enables output bash debugging" echo " -h | --help This help message" echo - #echo " --labelcolor Specify the color of label" + echo " --labelcolor Specify the color of label" echo " --nolabel Do not output label" echo " --noappname Do not output app name" echo " --noadjust Do not adjust the width of the label" } +# Message functions +msg_error() { + "${script_path}/tools/msg.sh" -a "msg.sh" error "${1}" +} + + # Parse options ARGUMENT="${@}" _opt_short="a:c:l:no:s:xh-:" -_opt_long="appname:,chr:,label:,nocolor,option:,space:,bash-debug,help,nolabel,noappname,noadjust" +_opt_long="appname:,chr:,label:,nocolor,option:,space:,bash-debug,help,labelcolor:,nolabel,noappname,noadjust" OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- ${ARGUMENT}) [[ ${?} != 0 ]] && exit 1 @@ -106,6 +113,40 @@ while true; do noadjust=true shift 1 ;; + --labelcolor) + customized_label_color=true + case ${2} in + "black") + labelcolor="30" + ;; + "red") + labelcolor="31" + ;; + "green") + labelcolor="32" + ;; + "yellow") + labelcolor="33" + ;; + "blue") + labelcolor="34" + ;; + "magenta") + labelcolor="35" + ;; + "cyan") + labelcolor="36" + ;; + "white") + labelcolor="37" + ;; + *) + msg_error "The wrong color." + exit 1 + ;; + esac + shift 2 + ;; --) shift break @@ -154,38 +195,38 @@ shift $((OPTIND - 1)) case ${1} in "info") msg_type="type" - textcolor="32" output="stdout" - [[ "${customized_label}" = false ]] && msg_label="Info" + [[ "${customized_label_color}" = false ]] && labelcolor="32" + [[ "${customized_label}" = false ]] && msg_label="Info" shift 1 ;; "warn") msg_type="warn" - textcolor="33" output="stdout" - [[ "${customized_label}" = false ]] && msg_label="Warning" + [[ "${customized_label_color}" = false ]] && labelcolor="33" + [[ "${customized_label}" = false ]] && msg_label="Warning" shift 1 ;; "debug") msg_type="debug" - textcolor="35" output="stdout" - [[ "${customized_label}" = false ]] && msg_label="Debug" + [[ "${customized_label_color}" = false ]] && labelcolor="35" + [[ "${customized_label}" = false ]] && msg_label="Debug" shift 1 ;; "error") msg_type="error" - textcolor="31" output="stderr" - [[ "${customized_label}" = false ]] && msg_label="Error" + [[ "${customized_label_color}" = false ]] && labelcolor="31" + [[ "${customized_label}" = false ]] && msg_label="Error" shift 1 ;; "") - "${script_path}/tools/msg.sh" -a "msg.sh" error "Please specify the message type" + msg_error "Please specify the message type" exit 1 ;; *) - "${script_path}/tools/msg.sh" -a "msg.sh" error "Unknown message type" + msg_error "Unknown message type" exit 1 ;; esac @@ -201,7 +242,7 @@ echo_type() { done fi if [[ "${nocolor}" = false ]]; then - echo -ne "\e[$([[ -v backcolor ]] && echo -n "${backcolor}"; [[ -v textcolor ]] && echo -n ";${textcolor}"; [[ -v decotypes ]] && echo -n ";${decotypes}")m${msg_label}\e[m " + echo -ne "\e[$([[ -v backcolor ]] && echo -n "${backcolor}"; [[ -v labelcolor ]] && echo -n ";${labelcolor}"; [[ -v decotypes ]] && echo -n ";${decotypes}")m${msg_label}\e[m " else echo -ne "${msg_label} " fi