44# EasyKey.shellmenu main script #
55# ################################
66
7+ # Colors
8+ clrBlack=0
9+ clrRed=1
10+ clrGreen=2
11+ clrYewllow=3
12+ clrBlue=4
13+ clrPurple=5
14+ clrCyan=6
15+ clrWhite=7
16+
717# Globals
8- waitonexit =true
18+ waitstatus =true
919continuemenu=true
1020globalClmWidth=45
1121immediateMode=false
1222actualmenu=" EasyKey.shellmenu"
23+ actualsubmenuname=" Your commands:"
24+ menuHeadingFGClr=" $clrWhite "
25+ menuHeadingBGClr=" $clrBlue "
26+ submenuFGClr=" $clrCyan "
27+ submenuBGClr=" $clrBlack "
1328
1429# ###########################
1530# ###########################
@@ -115,14 +130,17 @@ startMenu() {
115130# Colored log to standard out.
116131# Arguments:
117132# $1: log text
118- # $2: color code, e.g. "01;31"
133+ # $2: optional: foreground color (0-7)
134+ # $3: optional: background color (0-7)
119135# Outputs:
120136# Writes colored log to standard out
121137# ######################################
122138coloredLog () {
123- export GREP_COLOR=" $2 "
124- echo " $1 " | grep --color " .*"
125- export GREP_COLOR=' 01;31'
139+ set_foreground=$( tput setaf " ${2:- 7} " )
140+ set_background=$( tput setab " ${3:- 0} " )
141+ echo -n " $set_background$set_foreground "
142+ printf " %s\n" " $1 "
143+ tput sgr0
126144}
127145
128146# ######################################
@@ -135,7 +153,7 @@ coloredLog () {
135153# ######################################
136154blueLog () {
137155 log=" $1 "
138- coloredLog " ${log} " ' 1;37;44 '
156+ coloredLog " ${log} " " $clrWhite " " $clrBlue "
139157}
140158
141159# ######################################
@@ -148,7 +166,7 @@ blueLog() {
148166# ######################################
149167greenLog () {
150168 log=" $1 "
151- coloredLog " ${log} " ' 1;97;42 '
169+ coloredLog " ${log} " " $clrWhite " " $clrGreen "
152170}
153171
154172# ######################################
@@ -161,7 +179,7 @@ greenLog() {
161179# ######################################
162180redLog () {
163181 log=" $1 "
164- coloredLog " ${log} " ' 1;37;44 '
182+ coloredLog " ${log} " " $clrRed " " $clrBlack "
165183}
166184
167185# ######################################
@@ -172,9 +190,7 @@ redLog() {
172190# Writes log to standard out
173191# ######################################
174192importantLog () {
175- echo -e -n " \033[1;36m"
176- echo $1
177- echo -e -n ' \033[0m'
193+ coloredLog " $1 " " $clrCyan " " $clrBlack "
178194}
179195
180196# ################################################
@@ -291,7 +307,7 @@ selectFromCsv() {
291307 xdarkprocessing=" $5 "
292308 linefrom=${linefrom:= 2}
293309 lineto=${lineto:= 80}
294- coloredLog " ${csvfile} " ' 1;37;44 '
310+ importantLog " ${csvfile} "
295311 headers=$( head -1 " $csvfile " | sed ' s/ /_/g' \
296312 | awk -F, ' BEGIN {i=1} {while (i<=NF) {str=str substr($i,1,12)","; i++;}} END {print str}' )
297313 selectItem ' (echo "${headers}" && sed -n ' " ${linefrom} " ' ,' " ${lineto} " ' p "${csvfile}") \
@@ -319,7 +335,7 @@ coloredCsvTable() { #show csv file with header line in nice format
319335 heading=" $5 " # count of heading lines
320336 if [ " ${linefromXX} " = " 1" ]; then linefromXX=" 2" ; fi
321337 headers=$( head -1 $csvfile | sed ' s/ /_/g' | awk -F, ' BEGIN {i=1} {while (i<=NF) {str=str substr($i,1,12)","; i++;}} END {print str}' )
322- coloredLog " ${csvfile} " ' 1;37;44 '
338+ importantLog " ${csvfile} "
323339 ! [ " ${heading} " = " " ] && coloredLog " ${heading} "
324340 if [ " ${width} " = " " ]; then
325341 (echo " ${headers} " && sed -n " ${linefromXX} ,${linetoXX} p" " ${csvfile} " ) \
@@ -386,7 +402,7 @@ callKeyFunktion () {
386402 if [ " $1 " = " $keys2 " ]
387403 then
388404 method=$( echo " $i " | cut -f3 -d#)
389- clear && coloredLog " $method " ' 1;37;44 '
405+ clear && importantLog " $method "
390406 eval " $method "
391407 return 1
392408 fi
@@ -460,7 +476,7 @@ choice () {
460476 else
461477 callKeyFunktion " $REPLY "
462478 if [[ $? -gt 1 ]]; then
463- coloredLog " Huh ($request )?" " 1;31 "
479+ importantLog " Huh ($request )?"
464480 fi
465481 if $waitstatus ; then
466482 read -p $' \n <Press any key to return>' -n 1 -r
@@ -510,9 +526,7 @@ printMenuItem() {
510526# The menu head to stdout
511527# ################################################
512528printMenuHeading (){
513- export GREP_COLOR=' 1;37;44'
514- echo " $1 " | grep --color " .*"
515- export GREP_COLOR=' 01;31'
529+ coloredLog " $1 " " $menuHeadingFGClr " " $menuHeadingBGClr "
516530}
517531
518532# ################################################
@@ -523,9 +537,7 @@ printMenuHeading(){
523537# The sub menu head to stdout
524538# ################################################
525539printSubmenuHeading (){
526- export GREP_COLOR=' 1;36'
527- echo " $1 " | grep --color " .*"
528- export GREP_COLOR=' 01;31'
540+ coloredLog " $1 " " $submenuFGClr " " $submenuBGClr "
529541}
530542
531543quit () {
0 commit comments