Skip to content

Commit ec1bd67

Browse files
committed
Flexible column width in non-immediate mode
1 parent 8dea5e3 commit ec1bd67

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

EasyKey.maven/maven.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
88
source "$script_dir/../shellmenu.sh"
99
source "$script_dir/ezk-maven-functions.sh"
1010

11+
globalClmWidth=20
12+
1113
menuInit "Super MAVEN Home"
1214
submenuHead "Maven:"
1315
menuItemClm a "Clean all eclipse" "mvnCleanEclipse" b "Maven analyze dependencies" "mvn dependency:analyze"

shellmenu.sh

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ submenuHead () {
8181
menuItem () {
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
#################################################
106106
menuItemClm () {
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 () {
546547
printMenuItemClm() {
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

Comments
 (0)