From f88269fb22be89b73c60a56d9809ac4014b76320 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Tue, 18 Feb 2020 15:33:06 -0500 Subject: [PATCH] Don't send funky escape sequences as keypresses --- key.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/key.go b/key.go index f6233ee..6718cc6 100644 --- a/key.go +++ b/key.go @@ -78,6 +78,7 @@ const ( // Aliases const ( + KeyNull = keyNUL KeyBreak = keyETX KeyEnter = keyCR KeyBackspace = keyBS @@ -220,6 +221,12 @@ func ReadKey(r io.Reader) (Key, error) { return Key{Type: k}, nil } + // If the first byte is an escape sequence, and we're still here, just + // send a null to avoid sending bizarre escape sequences down the line + if n > 0 && buf[0] == 0x1b { + return Key{Type: KeyNull}, nil + } + // Nope, just a regular, ol' rune return Key{Type: KeyRune, Rune: c}, nil }