From 1c411ac48cff1de664c5f62ed0c86b1733859153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Prist=C3=A1=C5=A1=20Michal?= Date: Fri, 23 Oct 2015 13:16:45 +0200 Subject: [PATCH 1/5] changes completed --- terminal.go | 6 ++++++ utils.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/terminal.go b/terminal.go index 7afb025..cc66629 100644 --- a/terminal.go +++ b/terminal.go @@ -108,6 +108,12 @@ func (t *Terminal) ioloop() { } 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() + } + } } expectNextChar = true diff --git a/utils.go b/utils.go index 5f09bfd..f7d4adc 100644 --- a/utils.go +++ b/utils.go @@ -40,6 +40,8 @@ func IsPrintable(key rune) bool { // translate Esc[X func escapeExKey(r rune) rune { switch r { + case 51: + r = CharDeleteKey case 'D': r = CharBackward case 'C': @@ -48,6 +50,10 @@ func escapeExKey(r rune) rune { r = CharPrev case 'B': r = CharNext + case 'H': + r = CharLineStart + case 'F': + r = CharLineEnd } return r } From de44b285978803e2ac833bc15846d6bd1c42aba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Prist=C3=A1=C5=A1=20Michal?= Date: Fri, 23 Oct 2015 13:19:36 +0200 Subject: [PATCH 2/5] cleanup --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index f7d4adc..bbc4dc1 100644 --- a/utils.go +++ b/utils.go @@ -41,7 +41,7 @@ func IsPrintable(key rune) bool { func escapeExKey(r rune) rune { switch r { case 51: - r = CharDeleteKey + r = CharDelete case 'D': r = CharBackward case 'C': From 391c225c0bc553c1c49142a4875e67f789c8efc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Prist=C3=A1=C5=A1=20Michal?= Date: Mon, 26 Oct 2015 09:41:48 +0100 Subject: [PATCH 3/5] delete redundancy char check moved to escapeExKey method --- terminal.go | 8 +------- utils.go | 6 +++++- 2 files changed, 6 insertions(+), 8 deletions(-) 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': From 30303e5637907d7695d02a13e9480937514d1247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Prist=C3=A1=C5=A1=20Michal?= Date: Mon, 26 Oct 2015 09:43:34 +0100 Subject: [PATCH 4/5] reader nil check in escapeExKey --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index ba99a9b..4691c52 100644 --- a/utils.go +++ b/utils.go @@ -43,7 +43,7 @@ func escapeExKey(r rune, reader *bufio.Reader) rune { switch r { case 51: r = CharDelete - if d, _, err := reader.ReadRune(); err != nil || d != 126 { + if reader != nil && d, _, err := reader.ReadRune(); err != nil || d != 126 { reader.UnreadRune() } case 'D': From bcc2f0762c3f12a3a529470063a4b863633d5d42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Prist=C3=A1=C5=A1=20Michal?= Date: Mon, 26 Oct 2015 09:45:11 +0100 Subject: [PATCH 5/5] reader nil check in escapeExKey --- utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.go b/utils.go index 4691c52..efadd41 100644 --- a/utils.go +++ b/utils.go @@ -43,7 +43,7 @@ func escapeExKey(r rune, reader *bufio.Reader) rune { switch r { case 51: r = CharDelete - if reader != nil && d, _, err := reader.ReadRune(); err != nil || d != 126 { + if d, _, err := reader.ReadRune(); reader != nil && (err != nil || d != 126) { reader.UnreadRune() } case 'D':