@@ -81,6 +81,7 @@ submenuHead () {
8181menuItem () {
8282 menudatamap+=(" $1 $delimiter $2 $delimiter $3 $delimiter$actualsubmenuname$delimiter$actualmenu ${delimiter} 1" )
8383 ${immediateMode} && printMenuItem " $1 " " $2 "
84+ ${immediateMode} || update_column_width " $2 "
8485}
8586
8687# ################################################
@@ -98,16 +99,16 @@ menuItem () {
9899# menudatamap - the menu data
99100# actualsubmenuname - the actual submenu
100101# actualmenu - the actual main menu
101- # globalClmWidth - the column width
102102# Outputs:
103103# Adds menu item data to menudatamap array.
104104# Prints the menu item to standard out.
105105# ################################################
106106menuItemClm () {
107- clmLocalWidth=${globalClmWidth:= 45}
108107 menudatamap+=(" $1 $delimiter $2 $delimiter $3 $delimiter$actualsubmenuname$delimiter$actualmenu ${delimiter} 1" )
109108 menudatamap+=(" $4 $delimiter $5 $delimiter $6 $delimiter$actualsubmenuname$delimiter$actualmenu ${delimiter} 2" )
110109 ${immediateMode} && printMenuItemClm " $1 " " $2 " " $4 " " $5 "
110+ ${immediateMode} || update_column_width " $2 "
111+ ${immediateMode} || update_column_width " $5 "
111112}
112113
113114# ################################################
@@ -546,9 +547,9 @@ choice () {
546547printMenuItemClm () {
547548 echo -e " ${1} .,${2} ,${3} .,${4} " \
548549 | awk -F , -v OFS=, ' {printf "%-3s",$1;
549- printf "%-' " ${clmLocalWidth } " ' s",$2;
550+ printf "%-' " ${globalClmWidth } " ' s",$2;
550551 printf "%-3s",$3;
551- printf "%-' " ${clmLocalWidth } " ' s",$4;
552+ printf "%-' " ${globalClmWidth } " ' s",$4;
552553 printf("\n\r"); }'
553554}
554555
@@ -726,4 +727,21 @@ draw_border() {
726727
727728 # Print the bottom line of the square
728729 echo " +" $( printf " %-${max_length} s" | tr ' ' ' -' ) " +"
730+ }
731+
732+ # #####################################################
733+ # Updates global column width in non immediate mode
734+ # Arguments:
735+ # $1: string to measure (typically the menu item name)
736+ # Globals:
737+ # globalClmWidth - the global clm width setting
738+ # Output:
739+ # Updated globalClmWidth
740+ # #####################################################
741+ update_column_width () {
742+ desclength=${# 1}
743+ clmLocalWidth=$(( 3 + desclength + 3 ))
744+ if [ " $clmLocalWidth " -gt " $globalClmWidth " ]; then
745+ globalClmWidth=" $clmLocalWidth "
746+ fi
729747}
0 commit comments