forked from Mirrors/bubbletea
Don't send funky escape sequences as keypresses
This commit is contained in:
parent
3c6a2c1a52
commit
f88269fb22
7
key.go
7
key.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue