diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/term.sh | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/term.sh b/src/term.sh index 99487eb..daf2647 100644 --- a/src/term.sh +++ b/src/term.sh @@ -270,29 +270,46 @@ _term_get_byte() return 0 } +_term_get_escseq() +{ + local key=KEY_INVALID + + _term_get_byte + case "${term_byte}" in + 'A') key=KEY_UP;; + 'B') key=KEY_DOWN;; + 'C') key=KEY_RIGHT;; + 'D') key=KEY_LEFT;; + '3') + _term_get_byte + case "${term_byte}" in + '~') key=KEY_DEL;; + esac + ;; + esac + + printf '%s' "${key}" + return 0 +} + term_getch() { + local key=KEY_INVALID + _term_get_byte case "${term_byte}" in "$(printf '\033')") _term_get_byte case "${term_byte}" in '[') - _term_get_byte - case "${term_byte}" in - 'A') key=KEY_UP;; - 'B') key=KEY_DOWN;; - 'C') key=KEY_RIGHT;; - 'D') key=KEY_LEFT;; - *) key=KEY_INV;; - esac + key="$(_term_get_escseq)" ;; - *) key=KEY_INV;; esac ;; ' ') key=KEY_SPACE;; "${HT}") key=KEY_TAB;; "$(printf '\015')") key=KEY_ENTER;; + "$(printf '\177')") key=KEY_BACKSPACE;; *) key="${term_byte}";; esac |