Properly catch shift+tab

This commit is contained in:
Christian Rocha 2020-02-18 14:52:57 -05:00
parent d38a22380b
commit 3c6a2c1a52
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
1 changed files with 21 additions and 9 deletions

12
key.go
View File

@ -2,6 +2,7 @@ package tea
import (
"errors"
"fmt"
"io"
"unicode/utf8"
)
@ -127,6 +128,7 @@ const (
KeyDown
KeyRight
KeyLeft
KeyShiftTab
)
// Mapping for control keys to friendly consts
@ -171,6 +173,7 @@ var keyNames = map[int]string{
KeyDown: "down",
KeyRight: "right",
KeyLeft: "left",
KeyShiftTab: "shift+tab",
}
// Mapping for sequences to consts
@ -179,6 +182,7 @@ var sequences = map[string]KeyType{
"\x1b[B": KeyDown,
"\x1b[C": KeyRight,
"\x1b[D": KeyLeft,
"\x1b5B5A": KeyShiftTab,
}
// ReadKey reads keypress input from a TTY and returns a string representation
@ -192,6 +196,14 @@ func ReadKey(r io.Reader) (Key, error) {
return Key{}, err
}
// Hex representation of input sequence
hex := fmt.Sprintf("%x", buf[:n])
switch hex {
case "1b5b5a":
return Key{Type: KeyShiftTab}, nil
}
// Get rune
c, _ := utf8.DecodeRune(buf[:])
if c == utf8.RuneError {