added ability to read arrow keys (escape sequences)
This commit is contained in:
parent
bfa0c963f4
commit
a3ea826c4d
10
lesh
10
lesh
|
@ -135,15 +135,21 @@ quit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# infinite loop waiting for single character input
|
# infinite loop waiting for single character input
|
||||||
|
# or escape sequences from (e.g) arrow keys
|
||||||
key_loop() {
|
key_loop() {
|
||||||
while read -rs -n 1; do
|
while read -rs -n 1; do
|
||||||
|
# when escape recieved, read any characters sent immediately after
|
||||||
|
# if there are none, then the escape key was pressed, but is ignored
|
||||||
|
if [ "$REPLY" = $'\e' ]; then
|
||||||
|
read -rs -t 0.0001
|
||||||
|
fi
|
||||||
case $REPLY in
|
case $REPLY in
|
||||||
k)
|
k|"[A")
|
||||||
# if at start of the text, do nothing
|
# if at start of the text, do nothing
|
||||||
[ ! "$line" = 0 ] && scroll_up
|
[ ! "$line" = 0 ] && scroll_up
|
||||||
draw_prompt
|
draw_prompt
|
||||||
;;
|
;;
|
||||||
j)
|
j|"[B")
|
||||||
# if at the end of text, do nothing
|
# if at the end of text, do nothing
|
||||||
[ ! "$line" -ge $((${#text[@]}-scroll_size)) ] && scroll_down
|
[ ! "$line" -ge $((${#text[@]}-scroll_size)) ] && scroll_down
|
||||||
draw_prompt
|
draw_prompt
|
||||||
|
|
Loading…
Reference in New Issue