Files
sshtermy/third_party/ansi/parser_osc_test.go
T
db9979andClaude Opus 5.5 a68a375e3d Zeichnen noch einmal fast doppelt so schnell (#109)
* Leistungsanzeige verständlicher, Zeichnen etwa doppelt so schnell

- Anzeige bewertet die Zeichenzeit in Worten (flüssig/gut/etwas träge/ruckelt),
  zwei Zeilen Balken je Bild statt Braille-Punkte, "möglich"-Bildrate,
  1 Bild/s im Leerlauf wird erklärt; im Terminal links neben der F6-Leiste,
  Toasts weichen darunter aus
- Overlays (Toasts, Tooltip, Ausblenden, Leistungsanzeige) ohne Compositor:
  stamp() fasst nur die überdeckten Zeilen an
- Terminalbild wird gemerkt, solange keine neue Ausgabe kam (Term.Gen)
- Seitenleiste ohne lipgloss-Umbruch anfügen (beside), Verläufe in einem Render
- ViewHL misst bereits aufgefüllte Zeilen nicht noch einmal
- Benchmarks: Terminal 2,9 → 0,9 ms, mit F6 + Anzeige 6,5 → 2,3 ms,
  mit laufender Ausgabe 6,9 → 3,5 ms je Bild

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018i4GUk5KxaHH89KrFPon9n

* Zeichnen noch einmal fast doppelt so schnell

- x/ansi als Fork (third_party/ansi): ASCII-Schnellweg in FirstGraphemeCluster,
  lipgloss misst jede Zeile jedes Bildes
- Terminal-Zeilen unter einer Sperre holen (vt LineCopy), Farbregeln aus
  denselben Zellen statt jede Zelle zweimal einzeln
- Seitenleiste (F6, Ziel, …) gemerkt, solange ihr Inhalt gleich bleibt
- Balken der Leistungsanzeige je Farbe in einem Render
- Benchmark mit F6, Anzeige und laufender Ausgabe: 3,5 → 1,8 ms je Bild

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018i4GUk5KxaHH89KrFPon9n

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-09 13:02:55 +01:00

106 lines
2.3 KiB
Go

package ansi
import (
"fmt"
"strings"
"testing"
)
func TestOscSequence(t *testing.T) {
const maxBufferSize = 1024
cases := []testCase{
{
name: "parse",
input: "\x1b]2;charmbracelet: ~/Source/bubbletea\x07",
expected: []any{
[]byte("2;charmbracelet: ~/Source/bubbletea"),
},
},
{
name: "empty",
input: "\x1b]\x07",
expected: []any{
[]byte{},
},
},
{
name: "max_params",
input: fmt.Sprintf("\x1b]%s\x1b\\", strings.Repeat(";", 17)),
expected: []any{
[]byte(strings.Repeat(";", 17)),
Cmd('\\'),
},
},
{
name: "bell_terminated",
input: "\x1b]11;ff/00/ff\x07",
expected: []any{
[]byte("11;ff/00/ff"),
},
},
{
name: "esc_st_terminated",
input: "\x1b]11;ff/00/ff\x1b\\",
expected: []any{
[]byte("11;ff/00/ff"),
Cmd('\\'),
},
},
{
name: "utf8",
input: string([]byte{
0x1b, 0x5d, 0x32, 0x3b, 0x65, 0x63, 0x68, 0x6f, 0x20, 0x27,
0xc2, 0xaf, 0x5c, 0x5f, 0x28, 0xe3, 0x83, 0x84, 0x29, 0x5f,
0x2f, 0xc2, 0xaf, 0x27, 0x20, 0x26, 0x26, 0x20, 0x73, 0x6c,
0x65, 0x65, 0x70, 0x20, 0x31, 0x9c,
}),
expected: []any{
[]byte("2;echo '¯\\_(ツ)_/¯' && sleep 1"),
},
},
{
name: "string_terminator",
input: "\x1b]2;\xe6\x9c\xab\x1b\\",
expected: []any{
[]byte("2;\xe6"),
Cmd('\\'),
},
},
{
name: "exceed_max_buffer_size",
input: fmt.Sprintf("\x1b]52;s%s\x07", strings.Repeat("a", maxBufferSize)),
expected: []any{
fmt.Appendf(nil, "52;s%s", strings.Repeat("a", maxBufferSize-4)), // 4 is the len of "52;s"
},
},
{
name: "title_empty_params_esc",
input: "\x1b]0;abc\x1b\\\x1b];;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\x07",
expected: []any{
[]byte("0;abc"),
Cmd('\\'),
[]byte(strings.Repeat(";", 45)),
},
},
{
name: "just command",
input: "\x1b]112\x07",
expected: []any{
[]byte("112"),
},
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
dispatcher := &testDispatcher{}
parser := testParser(dispatcher)
parser.data = make([]byte, maxBufferSize)
parser.dataLen = maxBufferSize
parser.Parse([]byte(c.input))
assertEqual(t, len(c.expected), len(dispatcher.dispatched))
assertEqual(t, c.expected, dispatcher.dispatched)
})
}
}