Skip to content

Commit a26fe37

Browse files
committed
Global menu width calculated
1 parent bde6030 commit a26fe37

File tree

1 file changed

+8
-36
lines changed

1 file changed

+8
-36
lines changed

shellmenu.sh

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ clrWhite=7
1818
waitstatus=true # whether to wait for key press after menu command finished
1919
continuemenu=true # whether to continue menu loop (quit will set this to false)
2020
globalClmWidth=20 # the default (minimum) column width
21+
calculatedMenuWidth=43 # the calculated column width (internal)
2122
actualmenu="EasyKey.shellmenu" # the default menu heading
2223
actualsubmenuname="Your commands:" # the default sub menu heading
2324
menuHeadingFGClr="$clrWhite" # the default menu heading foreground color
@@ -562,11 +563,9 @@ printMenuHeading(){
562563
# The sub menu head to stdout
563564
#################################################
564565
printSubmenuHeading(){
565-
$has_two_clms && local dfltwidth=$(( globalClmWidth * 2 + 3 ))
566-
$has_two_clms || local dfltwidth=$(( globalClmWidth + 3 ))
567-
local width="${2:-$dfltwidth}"
566+
local width="${2:-$calculatedMenuWidth}"
568567
local symbol="${3:-""}"
569-
local paddedline="$(r_pad "$1" "$width" "$symbol")"
568+
local paddedline="$(r_pad "$1" "$width" "$symbol")"
570569
coloredLog "$paddedline\n\r" "$submenuFGClr" "$submenuBGClr"
571570
}
572571

@@ -639,7 +638,7 @@ draw_rounded_square() {
639638
done
640639
border+="$top_right_corner"
641640

642-
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)
641+
formattedMiddle=$(tput setaf $menuHeadingFGClr)$(tput setab $menuHeadingBGClr)$(tput bold)"$vertical_line "$(tput setaf $menuHeadingFGClr)$(tput setab $menuHeadingBGClr)$(tput bold)$text$(tput sgr0)$(tput setaf $menuHeadingFGClr)$(tput setab $menuHeadingBGClr)$(tput bold)" $vertical_line"$(tput sgr0)
643642

644643
formattedheading+=$(coloredLog "$border\n\r" 7 20)
645644
formattedheading+=$(printf '%s\n\r' "$formattedMiddle")
@@ -701,35 +700,6 @@ initConfig () {
701700
done <<< "$(echo -e "$configlines")"
702701
}
703702

704-
draw_border() {
705-
multiline_string="$1"
706-
707-
lines=()
708-
while IFS= read -r line; do
709-
lines+=("$line")
710-
done <<< "$multiline_string"
711-
712-
# Find the longest line length
713-
max_length=0
714-
for line in "${lines[@]}"; do
715-
length=${#line}
716-
if (( length > max_length )); then
717-
max_length=$length
718-
fi
719-
done
720-
721-
# Print the top line of the square
722-
echo "+"$(printf "%-${max_length}s" | tr ' ' '-')"+"
723-
724-
# Print the multiline string with side borders
725-
for line in "${lines[@]}"; do
726-
printf "| %-${max_length}s |\n" "$line"
727-
done
728-
729-
# Print the bottom line of the square
730-
echo "+"$(printf "%-${max_length}s" | tr ' ' '-')"+"
731-
}
732-
733703
######################################################
734704
# Updates global column width in non immediate mode
735705
# Arguments:
@@ -740,9 +710,11 @@ draw_border() {
740710
# Updated globalClmWidth
741711
######################################################
742712
update_column_width() {
743-
desclength=${#1}
744-
clmLocalWidth=$(( 3 + desclength + 3 ))
713+
local desclength=${#1}
714+
local clmLocalWidth=$(( 3 + desclength + 3 ))
745715
if [ "$clmLocalWidth" -gt "$globalClmWidth" ]; then
746716
globalClmWidth="$clmLocalWidth"
717+
$has_two_clms && calculatedMenuWidth=$(( globalClmWidth * 2 + 3 ))
718+
$has_two_clms || calculatedMenuWidth=$(( globalClmWidth + 3 ))
747719
fi
748720
}

0 commit comments

Comments
 (0)