diff --git a/spells/cantrips/menu b/spells/cantrips/menu index 17bec37..9a5c991 100755 --- a/spells/cantrips/menu +++ b/spells/cantrips/menu @@ -19,14 +19,14 @@ description=$1 shift # Parse args. Each arg is "name%command" -items="" -commands="" +declare -a items +# declare -a descriptions # not displayed so presently disabled +declare -a commands while [ ${#} -gt 0 ]; do - IFS='%' read -r item command < 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 + for i in "${!items[@]}"; do + # 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. + max_command_length=$(( $window_width - $max_name_length - 3 )) # -3 is for the > 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 } # Define the function to handle key presses