# declare -a descriptions # not displayed so presently disabled
declare -a commands
while [ ${#} -gt 0 ]; do
IFS='%' read -r item command <<EOF
$1
EOF
items="${items}:${item}"
commands="${commands}:${command}"
IFS='%' read -r -a option <<< "$1"
items+=("${option[0]}")
#descriptions+=("$(option[1])") # not displayed so presently disabled
commands+=("${option[1]}")
shift
done
@ -38,15 +38,14 @@ menu_x=$((0))
menu_y=$(fathom-cursor -y)
# Calculate the number of rows that the menu will occupy
num_rows=$(echo "$items" | tr -cd ':' | wc -c)
num_rows=${#items[@]}
# Calculate the maximum length of the item names
# Todo: abstract this out into a max-length function in another script. I gave up on trying to find an elegant way to pass a list of strings with spaces. Even separating them with newlines didn't work.
max_name_length=0
# Find the longest line
set -f IFS=':'; set -- $items; set +f
for line; do
for line in "${items[@]}"; do
line_length=${#line}
if [ $line_length -gt $max_name_length ]; then
max_name_length=$line_length
@ -55,7 +54,7 @@ done
# Make sure the menu items don't wrap, multiline menu items are not supported
window_width=$(fathom-terminal -w)
if [ "${max_name_length:-0}" -gt "${window_width:-80}" ]; then
if [ $max_name_length -gt $window_width ]; then
max_name_length=$window_width
fi
@ -80,21 +79,17 @@ display_menu() {
fi
# Print the items and commands
i=0
set -f IFS=':'; set -- $items; set +f
for item; do
set -f IFS=':'; set -- $commands; set +f
for j in $(seq 1 $selected); do shift; done
command=$1
max_command_length=$(( $window_width - $max_name_length - 3 )) # -3 is for the > and the space between item and command