Don't send funky escape sequences as keypresses

This commit is contained in:
Christian Rocha 2020-02-18 15:33:06 -05:00
parent 3c6a2c1a52
commit f88269fb22
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
1 changed files with 7 additions and 0 deletions

7
key.go
View File

@ -78,6 +78,7 @@ const (
// Aliases // Aliases
const ( const (
KeyNull = keyNUL
KeyBreak = keyETX KeyBreak = keyETX
KeyEnter = keyCR KeyEnter = keyCR
KeyBackspace = keyBS KeyBackspace = keyBS
@ -220,6 +221,12 @@ func ReadKey(r io.Reader) (Key, error) {
return Key{Type: k}, nil 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 // Nope, just a regular, ol' rune
return Key{Type: KeyRune, Rune: c}, nil return Key{Type: KeyRune, Rune: c}, nil
} }