Let's call sequences what they really are

This commit is contained in:
Christian Rocha 2020-01-14 17:15:17 -05:00
parent 8df1395e0a
commit 466d16b5a4
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
1 changed files with 5 additions and 5 deletions

10
key.go
View File

@ -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
} }