forked from Mirrors/bubbletea
Let's call sequences what they really are
This commit is contained in:
parent
8df1395e0a
commit
466d16b5a4
10
key.go
10
key.go
|
@ -18,7 +18,7 @@ const (
|
||||||
keyUS = 31
|
keyUS = 31
|
||||||
)
|
)
|
||||||
|
|
||||||
var controlKeyNames = map[int]string{
|
var controlNames = map[int]string{
|
||||||
keyETX: "ctrl+c",
|
keyETX: "ctrl+c",
|
||||||
keyLF: "enter",
|
keyLF: "enter",
|
||||||
keyCR: "enter",
|
keyCR: "enter",
|
||||||
|
@ -26,7 +26,7 @@ var controlKeyNames = map[int]string{
|
||||||
keyUS: "us",
|
keyUS: "us",
|
||||||
}
|
}
|
||||||
|
|
||||||
var keyNames = map[string]string{
|
var sequenceNames = map[string]string{
|
||||||
"\x1b[A": "up",
|
"\x1b[A": "up",
|
||||||
"\x1b[B": "down",
|
"\x1b[B": "down",
|
||||||
"\x1b[C": "right",
|
"\x1b[C": "right",
|
||||||
|
@ -52,13 +52,13 @@ func ReadKey(r io.Reader) (string, error) {
|
||||||
|
|
||||||
// Is it a control character?
|
// Is it a control character?
|
||||||
if n == 1 && c <= keyUS {
|
if n == 1 && c <= keyUS {
|
||||||
if s, ok := controlKeyNames[int(c)]; ok {
|
if s, ok := controlNames[int(c)]; ok {
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it a special key, like an arrow key?
|
// Is it a special sequence, like an arrow key?
|
||||||
if s, ok := keyNames[string(buf[:n])]; ok {
|
if s, ok := sequenceNames[string(buf[:n])]; ok {
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue