#!/bin/bash if [ "a$1" == "a--help" ] || [ "a$1" == "a-h" ]; then cat <"$tty" while true; do printf "\e[u\e[s\e[K" >"$tty" for ((i = 0; i < optionslength; i++)); do if [ "$i" -eq $sel ]; then printf "\e[30;47m" >"$tty" fi printf "%s\e[40;37m " "${options[$i]}" >"$tty" done case "$(./readkey <"$tty")" in left) sel=$((sel - 1)) ;; right) sel=$((sel + 1)) ;; q) printf "\e[u\e[KSelection aborted\n" >"$tty" exit 1 ;; enter) break ;; esac if ((sel < 0)); then sel=0 fi if ((sel >= optionslength)); then sel=$((optionslength - 1)) fi done printf "\e[u\e[KSelected %s\n" "${options[$sel]}" >"$tty" if [ "$printidx" -eq 1 ]; then echo "$sel" else echo "${options[$sel]}" fi