Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ func parseKittyKeyboard(params ansi.Params) (Event Event) {
}

case 2:
// shifted key + base key
// base key (PC-101 scancode position)
if b := rune(p.Param(1)); unicode.IsPrint(b) {
// XXX: When alternate key reporting is enabled, the protocol
// can return 3 things, the unicode codepoint of the key,
Expand All @@ -1423,7 +1423,6 @@ func parseKittyKeyboard(params ansi.Params) (Event Event) {
// when using a different language layout.
key.BaseCode = b
}
fallthrough

case 1:
// shifted key
Expand Down Expand Up @@ -1460,7 +1459,14 @@ func parseKittyKeyboard(params ansi.Params) (Event Event) {
}
case 2:
if code := p.Param(0); code != 0 {
key.Text += string(rune(code))
// The terminal may send the base code in text-as-codepoints
// instead of the actual shifted character. When Shift is
// active and ShiftedCode is available, use it instead.
if (key.Mod&ModShift) != 0 && key.ShiftedCode != 0 && code == int(key.BaseCode) {
key.Text += string(key.ShiftedCode)
} else {
key.Text += string(rune(code))
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,19 @@ func TestParseSequence(t *testing.T) {
[]byte("\x1b[97;;229u"),
[]Event{KeyPressEvent{Code: 'a', Text: "å"}},
},
// Cyrillic Shift+у on Ukrainian layout:
// unicode=1091(у), shifted=1059(У), base=101(e), mod=Shift, text=101(e, wrong)
// Text should be corrected to ShiftedCode (У) since terminal sent base code.
seqTest{
[]byte("\x1b[1091:1059:101;2;101u"),
[]Event{KeyPressEvent{Code: 'у', Text: "У", Mod: ModShift, ShiftedCode: 'У', BaseCode: 'e'}},
},
// Shift+4 on Ukrainian layout: terminal sends no sub-params,
// unicode=52(4), mod=Shift, text=59(;) — Text already correct.
seqTest{
[]byte("\x1b[52;2;59u"),
[]Event{KeyPressEvent{Code: '4', Text: ";", Mod: ModShift}},
},

// focus/blur
seqTest{
Expand Down