Files
sshtermy/third_party/ansi/parser_handler.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

61 lines
2.1 KiB
Go

package ansi
import "unsafe"
// Params represents a list of packed parameters.
type Params []Param
// Param returns the parameter at the given index and if it is part of a
// sub-parameters. It falls back to the default value if the parameter is
// missing. If the index is out of bounds, it returns the default value and
// false.
func (p Params) Param(i, def int) (int, bool, bool) {
if i < 0 || i >= len(p) {
return def, false, false
}
return p[i].Param(def), p[i].HasMore(), true
}
// ForEach iterates over the parameters and calls the given function for each
// parameter. If a parameter is part of a sub-parameter, it will be called with
// hasMore set to true.
// Use def to set a default value for missing parameters.
func (p Params) ForEach(def int, f func(i, param int, hasMore bool)) {
for i := range p {
f(i, p[i].Param(def), p[i].HasMore())
}
}
// ToParams converts a list of integers to a list of parameters.
func ToParams(params []int) Params {
return unsafe.Slice((*Param)(unsafe.Pointer(&params[0])), len(params))
}
// Handler handles actions performed by the parser.
// It is used to handle ANSI escape sequences, control characters, and runes.
type Handler struct {
// Print is called when a printable rune is encountered.
Print func(r rune)
// Execute is called when a control character is encountered.
Execute func(b byte)
// HandleCsi is called when a CSI sequence is encountered.
HandleCsi func(cmd Cmd, params Params)
// HandleEsc is called when an ESC sequence is encountered.
HandleEsc func(cmd Cmd)
// HandleDcs is called when a DCS sequence is encountered.
HandleDcs func(cmd Cmd, params Params, data []byte)
// HandleOsc is called when an OSC sequence is encountered.
HandleOsc func(cmd int, data []byte)
// HandlePm is called when a PM sequence is encountered.
HandlePm func(data []byte)
// HandleApc is called when an APC sequence is encountered.
HandleApc func(data []byte)
// HandleSos is called when a SOS sequence is encountered.
HandleSos func(data []byte)
}
// SetHandler sets the handler for the parser.
func (p *Parser) SetHandler(h Handler) {
p.handler = h
}