From a3ea826c4d7d61f7f6f5e31fabb07c918ec77669 Mon Sep 17 00:00:00 2001 From: rgybmc Date: Thu, 6 Aug 2020 14:15:44 +0100 Subject: [PATCH] added ability to read arrow keys (escape sequences) --- lesh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lesh b/lesh index 89b9173..923f207 100755 --- a/lesh +++ b/lesh @@ -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