added ability to read arrow keys (escape sequences)

This commit is contained in:
rgybmc 2020-08-06 14:15:44 +01:00
parent bfa0c963f4
commit a3ea826c4d
1 changed files with 8 additions and 2 deletions

10
lesh
View File

@ -135,15 +135,21 @@ quit() {
}
# infinite loop waiting for single character input
# or escape sequences from (e.g) arrow keys
key_loop() {
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
k)
k|"[A")
# if at start of the text, do nothing
[ ! "$line" = 0 ] && scroll_up
draw_prompt
;;
j)
j|"[B")
# if at the end of text, do nothing
[ ! "$line" -ge $((${#text[@]}-scroll_size)) ] && scroll_down
draw_prompt