@@ -14,6 +14,7 @@ msg_label=""
1414label_space=" 7"
1515adjust_chr=" "
1616customized_label=false
17+ customized_label_color=false
1718nolabel=false
1819noappname=false
1920noadjust=false
@@ -40,17 +41,23 @@ _help() {
4041 echo " -x | --bash-debug Enables output bash debugging"
4142 echo " -h | --help This help message"
4243 echo
43- # echo " --labelcolor Specify the color of label"
44+ echo " --labelcolor Specify the color of label"
4445 echo " --nolabel Do not output label"
4546 echo " --noappname Do not output app name"
4647 echo " --noadjust Do not adjust the width of the label"
4748}
4849
4950
51+ # Message functions
52+ msg_error () {
53+ " ${script_path} /tools/msg.sh" -a " msg.sh" error " ${1} "
54+ }
55+
56+
5057# Parse options
5158ARGUMENT=" ${@ } "
5259_opt_short=" a:c:l:no:s:xh-:"
53- _opt_long=" appname:,chr:,label:,nocolor,option:,space:,bash-debug,help,nolabel,noappname,noadjust"
60+ _opt_long=" appname:,chr:,label:,nocolor,option:,space:,bash-debug,help,labelcolor:, nolabel,noappname,noadjust"
5461OPT=$( getopt -o ${_opt_short} -l ${_opt_long} -- ${ARGUMENT} )
5562[[ ${?} != 0 ]] && exit 1
5663
@@ -106,6 +113,40 @@ while true; do
106113 noadjust=true
107114 shift 1
108115 ;;
116+ --labelcolor)
117+ customized_label_color=true
118+ case ${2} in
119+ " black" )
120+ labelcolor=" 30"
121+ ;;
122+ " red" )
123+ labelcolor=" 31"
124+ ;;
125+ " green" )
126+ labelcolor=" 32"
127+ ;;
128+ " yellow" )
129+ labelcolor=" 33"
130+ ;;
131+ " blue" )
132+ labelcolor=" 34"
133+ ;;
134+ " magenta" )
135+ labelcolor=" 35"
136+ ;;
137+ " cyan" )
138+ labelcolor=" 36"
139+ ;;
140+ " white" )
141+ labelcolor=" 37"
142+ ;;
143+ * )
144+ msg_error " The wrong color."
145+ exit 1
146+ ;;
147+ esac
148+ shift 2
149+ ;;
109150 --)
110151 shift
111152 break
@@ -154,38 +195,38 @@ shift $((OPTIND - 1))
154195case ${1} in
155196 " info" )
156197 msg_type=" type"
157- textcolor=" 32"
158198 output=" stdout"
159- [[ " ${customized_label} " = false ]] && msg_label=" Info"
199+ [[ " ${customized_label_color} " = false ]] && labelcolor=" 32"
200+ [[ " ${customized_label} " = false ]] && msg_label=" Info"
160201 shift 1
161202 ;;
162203 " warn" )
163204 msg_type=" warn"
164- textcolor=" 33"
165205 output=" stdout"
166- [[ " ${customized_label} " = false ]] && msg_label=" Warning"
206+ [[ " ${customized_label_color} " = false ]] && labelcolor=" 33"
207+ [[ " ${customized_label} " = false ]] && msg_label=" Warning"
167208 shift 1
168209 ;;
169210 " debug" )
170211 msg_type=" debug"
171- textcolor=" 35"
172212 output=" stdout"
173- [[ " ${customized_label} " = false ]] && msg_label=" Debug"
213+ [[ " ${customized_label_color} " = false ]] && labelcolor=" 35"
214+ [[ " ${customized_label} " = false ]] && msg_label=" Debug"
174215 shift 1
175216 ;;
176217 " error" )
177218 msg_type=" error"
178- textcolor=" 31"
179219 output=" stderr"
180- [[ " ${customized_label} " = false ]] && msg_label=" Error"
220+ [[ " ${customized_label_color} " = false ]] && labelcolor=" 31"
221+ [[ " ${customized_label} " = false ]] && msg_label=" Error"
181222 shift 1
182223 ;;
183224 " " )
184- " ${script_path} /tools/msg.sh " -a " msg.sh " error " Please specify the message type"
225+ msg_error " Please specify the message type"
185226 exit 1
186227 ;;
187228 * )
188- " ${script_path} /tools/msg.sh " -a " msg.sh " error " Unknown message type"
229+ msg_error " Unknown message type"
189230 exit 1
190231 ;;
191232esac
@@ -201,7 +242,7 @@ echo_type() {
201242 done
202243 fi
203244 if [[ " ${nocolor} " = false ]]; then
204- echo -ne " \e[$( [[ -v backcolor ]] && echo -n " ${backcolor} " ; [[ -v textcolor ]] && echo -n " ;${textcolor } " ; [[ -v decotypes ]] && echo -n " ;${decotypes} " ) m${msg_label} \e[m "
245+ echo -ne " \e[$( [[ -v backcolor ]] && echo -n " ${backcolor} " ; [[ -v labelcolor ]] && echo -n " ;${labelcolor } " ; [[ -v decotypes ]] && echo -n " ;${decotypes} " ) m${msg_label} \e[m "
205246 else
206247 echo -ne " ${msg_label} "
207248 fi
0 commit comments