@@ -29,6 +29,7 @@ delimiter=⊕
2929formattedTop=" "
3030formattedBottom=" "
3131formattedMiddle=" "
32+ generatedmenu=" "
3233
3334# ###########################
3435# ###########################
@@ -121,7 +122,10 @@ menuItemClm () {
121122startMenu () {
122123 while ${continuemenu:= true} ; do
123124 clear
124- generateMenu
125+ if [ " $generatedmenu " = " " ]; then
126+ generateMenu
127+ fi
128+ printf " $generatedmenu "
125129 choice " $1 "
126130 done
127131}
@@ -139,15 +143,41 @@ startMenu() {
139143# $1: log text
140144# $2: optional: foreground color (0-7)
141145# $3: optional: background color (0-7)
146+ # $4: optional: width of heading line
142147# Outputs:
143148# Writes colored log to standard out
144149# ######################################
145150coloredLog () {
146151 set_foreground=$( tput setaf " ${2:- $clrWhite } " )
147152 set_background=$( tput setab " ${3:- $clrBlack } " )
148153 echo -n " $set_background$set_foreground "
149- printf " %s\n " " $1 "
154+ printf " %s" " $1 "
150155 tput sgr0
156+ if [ $# -eq 4 ]; then
157+ length=${# 1}
158+ width=73
159+ pad=$(( width - length ))
160+ set_foreground=$( tput setaf " $3 " )
161+ set_background=$( tput setab " $clrBlack " )
162+ echo -n " $set_background$set_foreground "
163+ printf " %s" $( pad_string_with_stars " ─" $pad )
164+ tput sgr0
165+ fi
166+ printf " \n\r"
167+ }
168+
169+ pad_string_with_stars () {
170+ local string=" $1 "
171+ local count=" $2 "
172+ local padded_string=" "
173+
174+ for (( i = 0 ; i < count; i++ )) ; do
175+ padded_string+=" ─"
176+ done
177+
178+ padded_string+=" $string "
179+
180+ echo -n " $padded_string "
151181}
152182
153183# ######################################
@@ -278,7 +308,6 @@ selectItem () {
278308# Writes a colored or non-colored line to stdout
279309# ################################################
280310alternateRows () {
281- #! /bin/bash
282311 header=" $1 "
283312 i=1
284313 while read -r line
@@ -422,6 +451,7 @@ callKeyFunktion () {
422451# Generates the menu from the menudatamap.
423452# Globals:
424453# menudatamap - the menu data
454+ # generatedmenu - the generated menu (string)
425455# Outputs:
426456# the menu written to stdout
427457# ################################################
@@ -437,17 +467,17 @@ generateMenu () {
437467 fi
438468 IFS=" $delimiter " read -r key description action submenu menu column <<< " ${menudatamap[index]}"
439469 IFS=" $delimiter " read -r nextkey nextdescription nextaction nextsubmenu nextmenu nextcolumn <<< " ${menudatamap[((index+1))]}"
440- if [ " $index " -eq " 0" ]; then printMenuHeading " $menu " && echo ; fi
470+ if [ " $index " -eq " 0" ]; then generatedmenu+= $( printMenuHeading " $menu " ) ; fi
441471 if [ " $submenu " != " $previoussubmenu " ]; then
442- if [ " $submenucount " -gt 0 ]; then echo ; fi
443- printSubmenuHeading " $submenu " && echo ;
444- submenucount=$(( submenucount+ 1 )) ;
472+ if [ " $submenucount " -gt 0 ]; then generatedmenu+= $( printf " \n\r " ) ; fi
473+ generatedmenu+= $( printSubmenuHeading " $submenu " && echo)
474+ submenucount=$(( submenucount+ 1 )) ;
445475 fi
446476 if [ " $(( nextcolumn)) " -eq " $(( column + 1 )) " ]; then
447- printMenuItemClm " $key " " $description " " $nextkey " " $nextdescription "
477+ generatedmenu+= $( printMenuItemClm " $key " " $description " " $nextkey " " $nextdescription " )
448478 skipnext=true
449479 else
450- printMenuItem " $key " " $description "
480+ generatedmenu+= $( printMenuItem " $key " " $description " )
451481 fi
452482 previoussubmenu=" $submenu "
453483 done
@@ -519,7 +549,7 @@ printMenuItemClm() {
519549 printf "%-' " ${clmLocalWidth} " ' s",$2;
520550 printf "%-3s",$3;
521551 printf "%-' " ${clmLocalWidth} " ' s",$4;
522- printf("\n"); }'
552+ printf("\n\r "); }'
523553}
524554
525555# ################################################
@@ -531,7 +561,7 @@ printMenuItemClm() {
531561# The menu line to stdout
532562# ################################################
533563printMenuItem () {
534- echo " $1 . $2 "
564+ printf " %s. %s\n\r " " $1 " " $2 "
535565}
536566
537567# ################################################
@@ -610,8 +640,8 @@ draw_rounded_square() {
610640 formattedTop=$( tput setaf $clrWhite ) $( tput setab $clrBlue ) $( tput bold) $border $( tput sgr0)
611641 formattedMiddle=$( tput setaf $clrWhite ) $( tput setab $clrBlue ) $( tput bold) " $vertical_line " $( tput setaf $clrWhite ) $( tput setab $clrBlue ) $( tput bold) $text $( tput sgr0) $( tput setaf $clrWhite ) $( tput setab $clrBlue ) $( tput bold) " $vertical_line " $( tput sgr0)
612642
613- echo -e " $formattedTop "
614- echo -e " $formattedMiddle "
643+ printf " $formattedTop \n\r "
644+ printf " $formattedMiddle \n\r "
615645
616646 border=" $bottom_left_corner "
617647 for (( i= 0 ; i< width+ 2 ; i++ )) ; do
@@ -620,8 +650,9 @@ draw_rounded_square() {
620650 border+=" $bottom_right_corner "
621651
622652 formattedBottom=$( tput setaf $clrWhite ) $( tput setab $clrBlue ) $( tput bold) $border $( tput sgr0)
623- echo -e " $formattedBottom "
653+ printf " $formattedBottom \n\r "
624654
655+ printf " \n\r"
625656}
626657
627658# #####################################################
0 commit comments