tinybox
Handle a few more encodings of function keys and added up to F20
6832ed0ad9804ca41f9cf4a541670032b0fb17ef
salby <dsalby@gmail.com>
2026-02-23 22:40:01 +0000
pkg/tb.go | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/pkg/tb.go b/pkg/tb.go index 70f9a39..26ee1e8 100644 --- a/pkg/tb.go +++ b/pkg/tb.go @@ -165,6 +165,14 @@ const ( KeyF10 KeyF11 KeyF12 + KeyF13 + KeyF14 + KeyF15 + KeyF16 + KeyF17 + KeyF18 + KeyF19 + KeyF20 KeyHome KeyEnd KeyPageUp @@ -735,6 +743,10 @@ func parseSGRMouse(buf []byte) (Event, error) { return Event{Type: EventMouse, Button: mouseButton, X: x - 1, Y: y - 1, Press: press}, nil } +func isDecimal(c byte) bool { + return c >= '0' && c <= '9' +} + func parseDecimal(buf []byte, idx int) (value, next int, ok bool) { if idx >= len(buf) { return 0, idx, false @@ -806,15 +818,29 @@ func parseInput(buf []byte) (Event, error) { return parseMouseEvent(buf[3:6]) } } - if len(buf) >= 5 && buf[2] == '1' { - switch buf[3] { - case '1', '2', '3', '4', '5': - if buf[4] == '~' { - return Event{Type: EventKey, Key: Key(int(KeyF1) + int(buf[3]-'1'))}, nil - } + if len(buf) >= 4 && buf[2] == '[' && buf[3] >= 'A' && buf[3] <= 'E' { + return Event{Type: EventKey, Key: Key(int(KeyF1) + int(buf[3]-'A'))}, nil + } + if len(buf) >= 5 && buf[4] == '~' && isDecimal(buf[2]) && isDecimal(buf[3]) { + i := int((buf[2]-'0')*10 + (buf[3] - '0')) + switch i { + case 11, 12, 13, 14, 15: + return Event{Type: EventKey, Key: Key(int(KeyF1) + i - 11)}, nil + case 17, 18, 19, 20, 21: + return Event{Type: EventKey, Key: Key(int(KeyF1) + i - 12)}, nil + case 23, 24, 25, 26: + return Event{Type: EventKey, Key: Key(int(KeyF1) + i - 13)}, nil + case 28, 29: + return Event{Type: EventKey, Key: Key(int(KeyF1) + i - 14)}, nil + case 31, 32, 33, 34: + return Event{Type: EventKey, Key: Key(int(KeyF1) + i - 15)}, nil } } } + if len(buf) >= 3 && buf[1] == 'O' && buf[2] >= 'P' && buf[2] <= 'S' { + return Event{Type: EventKey, Key: Key(int(KeyF1) + int(buf[2]-'P'))}, nil + } + return Event{Type: EventKey, Key: KeyEscape}, nil }