# declare -a descriptions # not displayed so presently disabled
commands=""
declare -a commands
while [ ${#} -gt 0 ]; do
while [ ${#} -gt 0 ]; do
IFS='%' read -r -a option <<< "$1"
IFS='%' read -r item command <<EOF
items+=("${option[0]}")
$1
#descriptions+=("$(option[1])") # not displayed so presently disabled
EOF
commands+=("${option[1]}")
items="${items}:${item}"
commands="${commands}:${command}"
shift
shift
done
done
@ -38,14 +38,15 @@ menu_x=$((0))
menu_y=$(fathom-cursor -y)
menu_y=$(fathom-cursor -y)
# Calculate the number of rows that the menu will occupy
# Calculate the number of rows that the menu will occupy
num_rows=${#items[@]}
num_rows=$(echo "$items" | tr -cd ':' | wc -c)
# Calculate the maximum length of the item names
# 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.
# 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
max_name_length=0
# Find the longest line
# Find the longest line
for line in "${items[@]}"; do
set -f IFS=':'; set -- $items; set +f
for line; do
line_length=${#line}
line_length=${#line}
if [ $line_length -gt $max_name_length ]; then
if [ $line_length -gt $max_name_length ]; then
max_name_length=$line_length
max_name_length=$line_length
@ -79,17 +80,21 @@ display_menu() {
fi
fi
# Print the items and commands
# Print the items and commands
for i in "${!items[@]}"; do
i=0
# Truncate the command to the width of the screen # Todo: come up with a better solution that allows the user to see the full command.
set -f IFS=':'; set -- $items; set +f
max_command_length=$(( $window_width - $max_name_length - 3 )) # -3 is for the > and the space between item and command