mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
Don't send funky escape sequences as keypresses
This commit is contained in:
7
key.go
7
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user