diff options
author | P. J. McDermott <pj@pehjota.net> | 2015-10-28 23:49:42 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2015-10-28 23:55:07 (EDT) |
commit | abed96862ae06b59d07876b469586795860a3504 (patch) | |
tree | 2272978e09d2b6ed563244f644acba8f54f00b0d /src | |
parent | 89332994eb38982a8bd04ccc008bc5aba0c58908 (diff) | |
download | firman.sh-abed96862ae06b59d07876b469586795860a3504.zip firman.sh-abed96862ae06b59d07876b469586795860a3504.tar.gz firman.sh-abed96862ae06b59d07876b469586795860a3504.tar.bz2 |
term_getch(): Handle KEY_BACKSPACE and KEY_DEL
Also simplify invalid key code handling.
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 |