forked from Mirrors/bubbletea
Properly catch shift+tab
This commit is contained in:
parent
d38a22380b
commit
3c6a2c1a52
12
key.go
12
key.go
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue