diff options
| author | adamdotdevin <[email protected]> | 2025-07-10 15:49:49 -0500 |
|---|---|---|
| committer | adamdotdevin <[email protected]> | 2025-07-10 15:49:58 -0500 |
| commit | 294d0e7ee3476f4425c3d21fbaf82dfce3aba017 (patch) | |
| tree | 3c24c5caf7075612dc58ff4cdb1b1f87eedc2d9b /packages/tui/input/parse_test.go | |
| parent | 8be1ca836c806c5a3ea3f2f5b49a696063dd3a91 (diff) | |
| download | opencode-294d0e7ee3476f4425c3d21fbaf82dfce3aba017.tar.gz opencode-294d0e7ee3476f4425c3d21fbaf82dfce3aba017.zip | |
fix(tui): mouse wheel ansi codes leaking into editor
Diffstat (limited to 'packages/tui/input/parse_test.go')
| -rw-r--r-- | packages/tui/input/parse_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/packages/tui/input/parse_test.go b/packages/tui/input/parse_test.go new file mode 100644 index 000000000..dc892e0cd --- /dev/null +++ b/packages/tui/input/parse_test.go @@ -0,0 +1,47 @@ +package input + +import ( + "image/color" + "reflect" + "testing" + + "github.com/charmbracelet/x/ansi" +) + +func TestParseSequence_Events(t *testing.T) { + input := []byte("\x1b\x1b[Ztest\x00\x1b]10;rgb:1234/1234/1234\x07\x1b[27;2;27~\x1b[?1049;2$y\x1b[4;1$y") + want := []Event{ + KeyPressEvent{Code: KeyTab, Mod: ModShift | ModAlt}, + KeyPressEvent{Code: 't', Text: "t"}, + KeyPressEvent{Code: 'e', Text: "e"}, + KeyPressEvent{Code: 's', Text: "s"}, + KeyPressEvent{Code: 't', Text: "t"}, + KeyPressEvent{Code: KeySpace, Mod: ModCtrl}, + ForegroundColorEvent{color.RGBA{R: 0x12, G: 0x12, B: 0x12, A: 0xff}}, + KeyPressEvent{Code: KeyEscape, Mod: ModShift}, + ModeReportEvent{Mode: ansi.AltScreenSaveCursorMode, Value: ansi.ModeReset}, + ModeReportEvent{Mode: ansi.InsertReplaceMode, Value: ansi.ModeSet}, + } + + var p Parser + for i := 0; len(input) != 0; i++ { + if i >= len(want) { + t.Fatalf("reached end of want events") + } + n, got := p.parseSequence(input) + if !reflect.DeepEqual(got, want[i]) { + t.Errorf("got %#v (%T), want %#v (%T)", got, got, want[i], want[i]) + } + input = input[n:] + } +} + +func BenchmarkParseSequence(b *testing.B) { + var p Parser + input := []byte("\x1b\x1b[Ztest\x00\x1b]10;1234/1234/1234\x07\x1b[27;2;27~") + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + p.parseSequence(input) + } +} |
