-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathkitty.go
66 lines (61 loc) · 1.39 KB
/
kitty.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"strings"
"github.com/charmbracelet/x/ansi"
)
//nolint:mnd
func handleKitty(p *ansi.Parser) (string, error) {
flagDesc := func(flag int) string {
var r []string
if flag&1 != 0 {
r = append(r, "Disambiguate escape codes")
}
if flag&2 != 0 {
r = append(r, "Report event types")
}
if flag&4 != 0 {
r = append(r, "Report alternate keys")
}
if flag&8 != 0 {
r = append(r, "Report all keys as escape codes")
}
if flag&16 != 0 {
r = append(r, "Report associated text")
}
return strings.Join(r, ", ")
}
modeDesc := func(mode int) string {
switch mode {
case 1:
return "Set given flags and unset all others"
case 2:
return "Set given flags and keep existing flags unchanged"
case 3:
return "Unset given flags and keep existing flags unchanged"
default:
return "Unknown mode"
}
}
var first int
if n, ok := p.Param(0, 0); ok {
first = n
}
cmd := p.Cmd()
switch cmd.Marker() {
case '?':
return "Request Kitty keyboard", nil
case '>':
if first == 0 {
return "Disable Kitty keyboard", nil
}
return fmt.Sprintf("Push %q Kitty keyboard flag", flagDesc(first)), nil
case '<':
return fmt.Sprintf("Pop %d Kitty keyboard flags", first), nil
case '=':
if n, ok := p.Param(1, 0); ok {
return fmt.Sprintf("Set %q Kitty keyboard flags to %q", flagDesc(first), modeDesc(n)), nil
}
}
return "", errUnhandled
}