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

60 lines
1.4 KiB
Go

package sixel
import (
"fmt"
"io"
"strings"
)
// ErrInvalidRepeat is returned when a Repeat is invalid.
var ErrInvalidRepeat = fmt.Errorf("invalid repeat")
// WriteRepeat writes a Repeat to a writer. A repeat character is in the range
// of '?' (0x3F) to '~' (0x7E).
func WriteRepeat(w io.Writer, count int, char byte) (int, error) {
return fmt.Fprintf(w, "%c%d%c", RepeatIntroducer, count, char) //nolint:wrapcheck
}
// Repeat represents a Sixel repeat introducer.
type Repeat struct {
Count int
Char byte
}
// WriteTo writes a Repeat to a writer.
func (r Repeat) WriteTo(w io.Writer) (int64, error) {
n, err := WriteRepeat(w, r.Count, r.Char)
return int64(n), err
}
// String returns the Repeat as a string.
func (r Repeat) String() string {
var b strings.Builder
r.WriteTo(&b) //nolint:errcheck,gosec
return b.String()
}
// DecodeRepeat decodes a Repeat from a byte slice. It returns the Repeat and
// the number of bytes read.
func DecodeRepeat(data []byte) (r Repeat, n int) {
if len(data) == 0 || data[0] != RepeatIntroducer {
return r, n
}
if len(data) < 3 { // The minimum length is 3: the introducer, a digit, and a character.
return r, n
}
for n = 1; n < len(data); n++ {
if data[n] >= '0' && data[n] <= '9' {
r.Count = r.Count*10 + int(data[n]-'0')
} else {
r.Char = data[n]
n++ // Include the character in the count.
break
}
}
return r, n
}