diff --git a/spells/cantrips/menu b/spells/cantrips/menu index 9a5c991..0299459 100755 --- a/spells/cantrips/menu +++ b/spells/cantrips/menu @@ -19,14 +19,14 @@ description=$1 shift # Parse args. Each arg is "name%command" -declare -a items -# declare -a descriptions # not displayed so presently disabled -declare -a commands +items="" +commands="" while [ ${#} -gt 0 ]; do - IFS='%' read -r -a option <<< "$1" - items+=("${option[0]}") - #descriptions+=("$(option[1])") # not displayed so presently disabled - commands+=("${option[1]}") + IFS='%' read -r item command < and the space between item and command - truncated_command=$(echo "${commands[$i]}" | cut -c -$max_command_length) - if [ $i -eq $selected ]; then - printf "${CYAN}> %-${max_name_length}s${RESET} ${GREY}%s${RESET}\n" "${items[$i]}" "$truncated_command" - else - # Print the menu item plus extra spaces to cover up its command, since it's not selected - printf " %-${max_name_length}s %*s\n" "${items[$i]}" "${#truncated_command}" - fi - done + 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 + truncated_command=$(echo "${command}" | cut -c -$max_command_length) + if [ $i -eq $selected ]; then + printf "${CYAN}> %-${max_name_length}s${RESET} ${GREY}%s${RESET}\n" "${item}" "$truncated_command" + else + printf " %-${max_name_length}s %*s\n" "${item}" "${#truncated_command}" + fi + i=$((i + 1)) + done } # Define the function to handle key presses