return with numkey
This commit is contained in:
@@ -34,7 +34,9 @@ function select_option {
|
||||
get_cursor_row() { IFS=';' read -sdR -p $'\E[6n' ROW COL; echo ${ROW#*[}; }
|
||||
key_input() { read -s -n1 key1 2>/dev/null >&2
|
||||
read -s -n2 -t 0.1 key2 2>/dev/null >&2
|
||||
|
||||
if [[ "$key1" =~ ^[0-9]+$ ]]; then
|
||||
echo $key1; return;
|
||||
fi
|
||||
if [[ $key1$key2 = $ESC[A ]]; then echo up; return; fi
|
||||
if [[ $key1$key2 = $ESC[B ]]; then echo down; return; fi
|
||||
if [[ $key1 = $'\e' ]]; then echo esc; return; fi
|
||||
@@ -78,20 +80,21 @@ function select_option {
|
||||
done
|
||||
|
||||
# user key control
|
||||
case `key_input` in
|
||||
local user_input=`key_input`
|
||||
case "$user_input" in
|
||||
enter) break;;
|
||||
esc) reset_display; exit 1;;
|
||||
up) ((selected--));
|
||||
if [ $selected -lt 0 ]; then selected=$(($# - 1)); fi;;
|
||||
down) ((selected++));
|
||||
if [ $selected -ge $# ]; then selected=0; fi;;
|
||||
[0-9]) selected=$(( $user_input - 1 )); break;;
|
||||
esac
|
||||
done
|
||||
|
||||
# cursor position back to normal
|
||||
cursor_to $lastrow
|
||||
printf "\n"
|
||||
cursor_blink_on
|
||||
reset_display
|
||||
if [[ -n "$SELECT_TOFILE" ]]; then
|
||||
local idx=0
|
||||
for opt; do
|
||||
|
||||
Reference in New Issue
Block a user