Skip to content

Commit

Permalink
feat(input): support kitty alternate keys
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Feb 20, 2024
1 parent 5b20b45 commit 4b5344b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
20 changes: 17 additions & 3 deletions exp/term/input/ansi/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ func (d *driver) parseCsi(i int, p []byte, alt bool) (int, input.Event) {
}

seq += string(p[i])
log.Printf("csi seq: %q\r\n", seq)
csi := ansi.CsiSequence(seq)
initial := csi.Initial()
cmd := csi.Command()
Expand All @@ -317,8 +318,17 @@ func (d *driver) parseCsi(i int, p []byte, alt bool) (int, input.Event) {
if sym, ok := kittyKeyMap[code]; ok {
key.Sym = sym
} else {
key.Runes = []rune{rune(code)}
// TODO: support alternate keys
r := rune(code)
if !utf8.ValidRune(r) {
r = utf8.RuneError
}
key.Runes = []rune{r}
if len(params[0]) > 1 {
al := rune(params[0][1])
if utf8.ValidRune(al) {
key.AltRunes = []rune{al}
}
}
}
}
if len(params) > 1 {
Expand All @@ -338,7 +348,11 @@ func (d *driver) parseCsi(i int, p []byte, alt bool) (int, input.Event) {
}
}
if len(params) > 2 {
key.Runes = []rune{rune(params[2][0])}
r := rune(params[2][0])
if !utf8.ValidRune(r) {
r = utf8.RuneError
}
key.AltRunes = []rune{r}
}
return len(seq), key
}
Expand Down
3 changes: 3 additions & 0 deletions exp/term/input/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ func (k KeyEvent) String() string {
s += sym
}
}
if len(k.AltRunes) > 0 && string(k.Runes) != string(k.AltRunes) {
s += " [" + string(k.AltRunes) + "]"
}
switch k.Action {
case KeyRepeat:
s += " (repeat)"
Expand Down

0 comments on commit 4b5344b

Please sign in to comment.