Skip to content

Commit 221d35f

Browse files
committed
Colors refactored
1 parent c578bb1 commit 221d35f

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

EasyKey.kubectl/ezk-kubectl-functions.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function addContext() {
5555
}
5656

5757
function showPodManifest() {
58-
selectItem "kubectl get pods" "awk '{print \$1}'" 100 1 "2"
58+
selectItem "kubectl get pods" "awk '{print \$1}'" 100 1 ""
5959
if [[ $fname == "" ]]; then return 0; fi
6060
executeCommand "kubectl get pods $fname -o yaml"
6161
}

shellmenu.sh

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@
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
919
continuemenu=true
1020
globalClmWidth=45
1121
immediateMode=false
1222
actualmenu="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
#######################################
122138
coloredLog () {
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
#######################################
136154
blueLog() {
137155
log="$1"
138-
coloredLog "${log}" '1;37;44'
156+
coloredLog "${log}" "$clrWhite" "$clrBlue"
139157
}
140158

141159
#######################################
@@ -148,7 +166,7 @@ blueLog() {
148166
#######################################
149167
greenLog() {
150168
log="$1"
151-
coloredLog "${log}" '1;97;42'
169+
coloredLog "${log}" "$clrWhite" "$clrGreen"
152170
}
153171

154172
#######################################
@@ -161,7 +179,7 @@ greenLog() {
161179
#######################################
162180
redLog() {
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
#######################################
174192
importantLog() {
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
#################################################
512528
printMenuHeading(){
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
#################################################
525539
printSubmenuHeading(){
526-
export GREP_COLOR='1;36'
527-
echo "$1" | grep --color ".*"
528-
export GREP_COLOR='01;31'
540+
coloredLog "$1" "$submenuFGClr" "$submenuBGClr"
529541
}
530542

531543
quit () {

0 commit comments

Comments
 (0)