diff --git a/terminal.go b/terminal.go index cc66629..381f01d 100644 --- a/terminal.go +++ b/terminal.go @@ -107,13 +107,7 @@ func (t *Terminal) ioloop() { r = escapeKey(r) } else if isEscapeEx { isEscapeEx = false - r = escapeExKey(r) - // if hw delete button is pressed it is specified as set ot 4 runes [27,91,51,126]. we are now at 51 - if r == CharDelete { - if d, _, err := buf.ReadRune(); err != nil || d != 126 { - buf.UnreadRune() - } - } + r = escapeExKey(r, buf) } expectNextChar = true diff --git a/utils.go b/utils.go index bbc4dc1..ba99a9b 100644 --- a/utils.go +++ b/utils.go @@ -1,6 +1,7 @@ package readline import ( + "bufio" "strconv" "syscall" @@ -38,10 +39,13 @@ func IsPrintable(key rune) bool { } // translate Esc[X -func escapeExKey(r rune) rune { +func escapeExKey(r rune, reader *bufio.Reader) rune { switch r { case 51: r = CharDelete + if d, _, err := reader.ReadRune(); err != nil || d != 126 { + reader.UnreadRune() + } case 'D': r = CharBackward case 'C':