on master help sign in
utils/lib.sh: colorize messages
56a93eeMarkus Heiser
utils/filtron.sh+4−2
@@ -287,7 +287,7 @@ remove_user() {
287}
287}
288
288
289interactive_shell(){
289interactive_shell(){
290− echo "// exit with CTRL-D"
290+ echo "// exit with ${_BCyan}CTRL-D${_creset}"
291 sudo -H -u ${SERVICE_USER} -i
291 sudo -H -u ${SERVICE_USER} -i
292}
292}
293
293
@@ -397,7 +397,9 @@ EOF
397 echo
397 echo
398 systemctl --no-pager -l status filtron.service
398 systemctl --no-pager -l status filtron.service
399 echo
399 echo
400+ # shellcheck disable=SC2059
400− read -r -s -n1 -t 2 -p "// use CTRL-C to stop monitoring the log"
401+ printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
402+ read -r -s -n1 -t 2
401 echo
403 echo
402 while true; do
404 while true; do
403 trap break 2
405 trap break 2
utils/lib.sh+56−22
@@ -75,13 +75,50 @@ required_commands() {
75 return $exit_val
75 return $exit_val
76}
76}
77
77
78+# colors
79+# ------
80+
81+# shellcheck disable=SC2034
82+set_terminal_colors() {
83+ _colors=8
84+ _creset='\e[0m' # reset all attributes
85+
86+ _Black='\e[0;30m'
87+ _White='\e[1;37m'
88+ _Red='\e[0;31m'
89+ _Green='\e[0;32m'
90+ _Yellow='\e[0;33m'
91+ _Blue='\e[0;34m'
92+ _Violet='\e[0;35m'
93+ _Cyan='\e[0;36m'
94+
95+ _BBlack='\e[1;30m'
96+ _BWhite='\e[1;37m'
97+ _BRed='\e[1;31m'
98+ _BGreen='\e[1;32m'
99+ _BYellow='\e[1;33m'
100+ _BBlue='\e[1;34m'
101+ _BPurple='\e[1;35m'
102+ _BCyan='\e[1;36m'
103+}
104+set_terminal_colors
105+
106+# reST
107+# ----
108+
109+if command -v fmt >/dev/null; then
110+ export FMT="fmt -u"
111+else
112+ export FMT="cat"
113+fi
114+
78rst_title() {
115rst_title() {
79 # usage: rst_title <header-text> [part|chapter|section]
116 # usage: rst_title <header-text> [part|chapter|section]
80
117
81 case ${2-chapter} in
118 case ${2-chapter} in
82− part) printf "\n${1//?/=}\n$1\n${1//?/=}\n";;
119+ part) printf "\n${_BGreen}${1//?/=}\n$1\n${1//?/=}${_creset}\n";;
83− chapter) printf "\n${1}\n${1//?/=}\n";;
120+ chapter) printf "\n${_BGreen}${1}\n${1//?/=}${_creset}\n";;
84− section) printf "\n${1}\n${1//?/-}\n";;
121+ section) printf "\n${_BGreen}${1}\n${1//?/-}${_creset}\n";;
85 *)
122 *)
86 err_msg "invalid argument '${2}' in line $(caller)"
123 err_msg "invalid argument '${2}' in line $(caller)"
87 return 42
124 return 42
@@ -89,12 +126,6 @@ rst_title() {
89 esac
126 esac
90}
127}
91
128
92−if command -v fmt >/dev/null; then
93− export FMT="fmt -u"
94−else
95− export FMT="cat"
96−fi
97−
98rst_para() {
129rst_para() {
99 # usage: RST_INDENT=1 rst_para "lorem ipsum ..."
130 # usage: RST_INDENT=1 rst_para "lorem ipsum ..."
100 local prefix=''
131 local prefix=''
@@ -106,9 +137,9 @@ rst_para() {
106 fi
137 fi
107}
138}
108
139
109−err_msg() { echo -e "ERROR: $*" >&2; }
140+err_msg() { echo -e "${_BRed}ERROR:${_creset} $*" >&2; }
110−warn_msg() { echo -e "WARN: $*" >&2; }
141+warn_msg() { echo -e "${_BBlue}WARN:${_creset} $*" >&2; }
111−info_msg() { echo -e "INFO: $*"; }
142+info_msg() { echo -e "${_BYellow}INFO:${_creset} $*" >&2; }
112
143
113clean_stdin() {
144clean_stdin() {
114 if [[ $(uname -s) != 'Darwin' ]]; then
145 if [[ $(uname -s) != 'Darwin' ]]; then
@@ -121,11 +152,14 @@ wait_key(){
121
152
122 clean_stdin
153 clean_stdin
123 local _t=$1
154 local _t=$1
124− local msg="${MSG:-** press any [KEY] to continue **}"
155+ local msg="${MSG}"
156+ [[ -z "$msg" ]] && msg="${_Green}** press any [${_BCyan}KEY${_Green}] to continue **${_creset}"
157+
125 [[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
158 [[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
126 [[ ! -z $_t ]] && _t="-t $_t"
159 [[ ! -z $_t ]] && _t="-t $_t"
160+ printf "$msg"
127 # shellcheck disable=SC2086
161 # shellcheck disable=SC2086
128− read -r -s -n1 $_t -p "$msg"
162+ read -r -s -n1 $_t
129 echo
163 echo
130 clean_stdin
164 clean_stdin
131}
165}
@@ -142,12 +176,12 @@ ask_yn() {
142 case "${2}" in
176 case "${2}" in
143 Yn)
177 Yn)
144 local exit_val=${EXIT_YES}
178 local exit_val=${EXIT_YES}
145− local choice="[YES/no]"
179+ local choice="[${_BGreen}YES${_creset}/no]"
146 local default="Yes"
180 local default="Yes"
147 ;;
181 ;;
148 *)
182 *)
149 local exit_val=${EXIT_NO}
183 local exit_val=${EXIT_NO}
150− local choice="[NO/yes]"
184+ local choice="[${_BGreen}NO${_creset}/yes]"
151 local default="No"
185 local default="No"
152 ;;
186 ;;
153 esac
187 esac
@@ -201,7 +235,7 @@ prefix_stdout () {
201
235
202 local prefix=" | "
236 local prefix=" | "
203
237
204− if [[ ! -z $1 ]] ; then prefix="$1"; fi
238+ if [[ ! -z $1 ]] ; then prefix="${_BYellow}$1${_creset}"; fi
205
239
206 # shellcheck disable=SC2162
240 # shellcheck disable=SC2162
207 (while IFS= read line; do
241 (while IFS= read line; do
@@ -270,17 +304,17 @@ choose_one() {
270 [[ ! -z $_t ]] && _t="-t $_t"
304 [[ ! -z $_t ]] && _t="-t $_t"
271
305
272 list=("$@")
306 list=("$@")
273− echo -e "Menu::"
307+ echo -e "${_BGreen}Menu::${_creset}"
274 for ((i=1; i<= $((max -1)); i++)); do
308 for ((i=1; i<= $((max -1)); i++)); do
275 if [[ "$i" == "$default" ]]; then
309 if [[ "$i" == "$default" ]]; then
276− echo -e " $i.) ${list[$i]} [default]"
310+ echo -e " ${_BGreen}$i.${_creset}) ${list[$i]} [default]"
277 else
311 else
278 echo -e " $i.) ${list[$i]}"
312 echo -e " $i.) ${list[$i]}"
279 fi
313 fi
280 done
314 done
281 while true; do
315 while true; do
282 clean_stdin
316 clean_stdin
283− printf "$1 [$default] "
317+ printf "$1 [${_BGreen}$default${_creset}] "
284
318
285 if (( 10 > max )); then
319 if (( 10 > max )); then
286 # shellcheck disable=SC2086
320 # shellcheck disable=SC2086
@@ -403,11 +437,11 @@ install_template() {
403 ;;
437 ;;
404 "interactiv shell")
438 "interactiv shell")
405 echo "// edit ${dst} to your needs"
439 echo "// edit ${dst} to your needs"
406− echo "// exit with CTRL-D"
440+ echo "// exit with ${_BCyan}CTRL-D${_creset}"
407 sudo -H -u "${owner}" -i
441 sudo -H -u "${owner}" -i
408 $DIFF_CMD "${dst}" "${template_file}"
442 $DIFF_CMD "${dst}" "${template_file}"
409 echo
443 echo
410− echo "did you edit file ..."
444+ echo "${_BBlack}did you edit file ...${_creset}"
411 printf " ${template_file}"
445 printf " ${template_file}"
412 if ask_yn "... to your needs?"; then
446 if ask_yn "... to your needs?"; then
413 break
447 break
utils/searx.sh+6−4
@@ -445,9 +445,9 @@ deactivate_service() {
445 uWSGI_restart
445 uWSGI_restart
446}
446}
447
447
448−interactive_shell() {
448+interactive_shell(){
449− echo "// exit with CTRL-D"
449+ echo "// exit with ${_BCyan}CTRL-D${_creset}"
450− sudo -H -u "${SERVICE_USER}" -i
450+ sudo -H -u ${SERVICE_USER} -i
451}
451}
452
452
453git_diff() {
453git_diff() {
@@ -534,7 +534,9 @@ EOF
534 echo
534 echo
535 systemctl --no-pager -l status uwsgi.service
535 systemctl --no-pager -l status uwsgi.service
536 echo
536 echo
537+ # shellcheck disable=SC2059
537− read -r -s -n1 -t 2 -p "// use CTRL-C to stop monitoring the log"
538+ printf "// use ${_BCyan}CTRL-C${_creset} to stop monitoring the log"
539+ read -r -s -n1 -t 2
538 echo
540 echo
539 while true; do
541 while true; do
540 trap break 2
542 trap break 2