Fix a bug in the Go code of the CSI key event parser

Fixes #6189
This commit is contained in:
Kovid Goyal 2023-04-16 15:31:56 +05:30
parent b314303787
commit 91700b3e42
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 46 additions and 10 deletions

View File

@ -40,6 +40,8 @@ Detailed list of changes
- Fix a regression in the previous release that broke the remote file kitten (:iss:`6186`)
- Fix a regression in the previous release that broke handling of some key board shortcuts in some kittens on some keyboard layouts (:iss:`6189`)
0.28.0 [2023-04-15]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -140,26 +140,30 @@ func KeyEventFromCSI(csi string) *KeyEvent {
csi = csi[:len(csi)-1]
sections := strings.Split(csi, ";")
get_sub_sections := func(section string) []int {
get_sub_sections := func(section string, missing int) []int {
p := strings.Split(section, ":")
ans := make([]int, len(p))
for i, x := range p {
q, err := strconv.Atoi(x)
if err != nil {
return nil
if x == "" {
ans[i] = missing
} else {
q, err := strconv.Atoi(x)
if err != nil {
return nil
}
ans[i] = q
}
ans[i] = q
}
return ans
}
first_section := get_sub_sections(sections[0])
second_section := make([]int, 0)
third_section := make([]int, 0)
first_section := get_sub_sections(sections[0], 0)
second_section := []int{}
third_section := []int{}
if len(sections) > 1 {
second_section = get_sub_sections(sections[1])
second_section = get_sub_sections(sections[1], 1)
}
if len(sections) > 2 {
third_section = get_sub_sections(sections[2])
third_section = get_sub_sections(sections[2], 0)
}
var ans = KeyEvent{Type: PRESS}
var keynum int

View File

@ -0,0 +1,30 @@
// License: GPLv3 Copyright: 2023, Kovid Goyal, <kovid at kovidgoyal.net>
package loop
import (
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
)
var _ = fmt.Print
func TestKeyEventFromCSI(t *testing.T) {
test_text := func(csi string, expected, alternate string) {
ev := KeyEventFromCSI(csi)
if ev == nil {
t.Fatalf("Failed to get parse %#v", csi)
}
if diff := cmp.Diff(expected, ev.Text); diff != "" {
t.Fatalf("Failed to get text from %#v:\n%s", csi, diff)
}
if diff := cmp.Diff(alternate, ev.AlternateKey); diff != "" {
t.Fatalf("Failed to get alternate from %#v:\n%s", csi, diff)
}
}
test_text("121;;121u", "y", "")
test_text("121::122;;121u", "y", "z")
}