From abed96862ae06b59d07876b469586795860a3504 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Wed, 28 Oct 2015 23:49:42 -0400 Subject: term_getch(): Handle KEY_BACKSPACE and KEY_DEL Also simplify invalid key code handling. --- (limited to 'src') 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 -- cgit v0.9.1