forked from Mirrors/bubbletea
Properly catch shift+tab
This commit is contained in:
parent
d38a22380b
commit
3c6a2c1a52
30
key.go
30
key.go
|
@ -2,6 +2,7 @@ package tea
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
@ -127,6 +128,7 @@ const (
|
||||||
KeyDown
|
KeyDown
|
||||||
KeyRight
|
KeyRight
|
||||||
KeyLeft
|
KeyLeft
|
||||||
|
KeyShiftTab
|
||||||
)
|
)
|
||||||
|
|
||||||
// Mapping for control keys to friendly consts
|
// Mapping for control keys to friendly consts
|
||||||
|
@ -166,19 +168,21 @@ var keyNames = map[int]string{
|
||||||
keySP: "space",
|
keySP: "space",
|
||||||
keyDEL: "delete",
|
keyDEL: "delete",
|
||||||
|
|
||||||
KeyRune: "rune",
|
KeyRune: "rune",
|
||||||
KeyUp: "up",
|
KeyUp: "up",
|
||||||
KeyDown: "down",
|
KeyDown: "down",
|
||||||
KeyRight: "right",
|
KeyRight: "right",
|
||||||
KeyLeft: "left",
|
KeyLeft: "left",
|
||||||
|
KeyShiftTab: "shift+tab",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mapping for sequences to consts
|
// Mapping for sequences to consts
|
||||||
var sequences = map[string]KeyType{
|
var sequences = map[string]KeyType{
|
||||||
"\x1b[A": KeyUp,
|
"\x1b[A": KeyUp,
|
||||||
"\x1b[B": KeyDown,
|
"\x1b[B": KeyDown,
|
||||||
"\x1b[C": KeyRight,
|
"\x1b[C": KeyRight,
|
||||||
"\x1b[D": KeyLeft,
|
"\x1b[D": KeyLeft,
|
||||||
|
"\x1b5B5A": KeyShiftTab,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadKey reads keypress input from a TTY and returns a string representation
|
// 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
|
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
|
// Get rune
|
||||||
c, _ := utf8.DecodeRune(buf[:])
|
c, _ := utf8.DecodeRune(buf[:])
|
||||||
if c == utf8.RuneError {
|
if c == utf8.RuneError {
|
||||||
|
|
Loading…
Reference in New Issue