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