mirror of
https://github.com/db9979/sshtermy.git
synced 2026-12-06 20:54:09 +01:00
* 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>
179 lines
5.0 KiB
Go
179 lines
5.0 KiB
Go
package ansi
|
|
|
|
import (
|
|
"fmt"
|
|
"image/color"
|
|
|
|
"github.com/lucasb-eyer/go-colorful"
|
|
)
|
|
|
|
// HexColor is a [color.Color] that can be formatted as a hex string.
|
|
type HexColor string
|
|
|
|
// RGBA returns the RGBA values of the color.
|
|
func (h HexColor) RGBA() (r, g, b, a uint32) {
|
|
hex := h.color()
|
|
if hex == nil {
|
|
return 0, 0, 0, 0
|
|
}
|
|
return hex.RGBA()
|
|
}
|
|
|
|
// Hex returns the hex representation of the color. If the color is invalid, it
|
|
// returns an empty string.
|
|
func (h HexColor) Hex() string {
|
|
hex := h.color()
|
|
if hex == nil {
|
|
return ""
|
|
}
|
|
return hex.Hex()
|
|
}
|
|
|
|
// String returns the color as a hex string. If the color is nil, an empty
|
|
// string is returned.
|
|
func (h HexColor) String() string {
|
|
return h.Hex()
|
|
}
|
|
|
|
// color returns the underlying color of the HexColor.
|
|
func (h HexColor) color() *colorful.Color {
|
|
hex, err := colorful.Hex(string(h))
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return &hex
|
|
}
|
|
|
|
// XRGBColor is a [color.Color] that can be formatted as an XParseColor
|
|
// rgb: string.
|
|
//
|
|
// See: https://linux.die.net/man/3/xparsecolor
|
|
type XRGBColor struct {
|
|
color.Color
|
|
}
|
|
|
|
// RGBA returns the RGBA values of the color.
|
|
func (x XRGBColor) RGBA() (r, g, b, a uint32) {
|
|
if x.Color == nil {
|
|
return 0, 0, 0, 0
|
|
}
|
|
return x.Color.RGBA()
|
|
}
|
|
|
|
// String returns the color as an XParseColor rgb: string. If the color is nil,
|
|
// an empty string is returned.
|
|
func (x XRGBColor) String() string {
|
|
if x.Color == nil {
|
|
return ""
|
|
}
|
|
r, g, b, _ := x.Color.RGBA()
|
|
// Get the lower 8 bits
|
|
return fmt.Sprintf("rgb:%04x/%04x/%04x", r, g, b)
|
|
}
|
|
|
|
// XRGBAColor is a [color.Color] that can be formatted as an XParseColor
|
|
// rgba: string.
|
|
//
|
|
// See: https://linux.die.net/man/3/xparsecolor
|
|
type XRGBAColor struct {
|
|
color.Color
|
|
}
|
|
|
|
// RGBA returns the RGBA values of the color.
|
|
func (x XRGBAColor) RGBA() (r, g, b, a uint32) {
|
|
if x.Color == nil {
|
|
return 0, 0, 0, 0
|
|
}
|
|
return x.Color.RGBA()
|
|
}
|
|
|
|
// String returns the color as an XParseColor rgba: string. If the color is nil,
|
|
// an empty string is returned.
|
|
func (x XRGBAColor) String() string {
|
|
if x.Color == nil {
|
|
return ""
|
|
}
|
|
r, g, b, a := x.RGBA()
|
|
// Get the lower 8 bits
|
|
return fmt.Sprintf("rgba:%04x/%04x/%04x/%04x", r, g, b, a)
|
|
}
|
|
|
|
// SetForegroundColor returns a sequence that sets the default terminal
|
|
// foreground color.
|
|
//
|
|
// OSC 10 ; color ST
|
|
// OSC 10 ; color BEL
|
|
//
|
|
// Where color is the encoded color number. Most terminals support hex,
|
|
// XParseColor rgb: and rgba: strings. You could use [HexColor], [XRGBColor],
|
|
// or [XRGBAColor] to format the color.
|
|
//
|
|
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
|
|
func SetForegroundColor(s string) string {
|
|
return "\x1b]10;" + s + "\x07"
|
|
}
|
|
|
|
// RequestForegroundColor is a sequence that requests the current default
|
|
// terminal foreground color.
|
|
//
|
|
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
|
|
const RequestForegroundColor = "\x1b]10;?\x07"
|
|
|
|
// ResetForegroundColor is a sequence that resets the default terminal
|
|
// foreground color.
|
|
//
|
|
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
|
|
const ResetForegroundColor = "\x1b]110\x07"
|
|
|
|
// SetBackgroundColor returns a sequence that sets the default terminal
|
|
// background color.
|
|
//
|
|
// OSC 11 ; color ST
|
|
// OSC 11 ; color BEL
|
|
//
|
|
// Where color is the encoded color number. Most terminals support hex,
|
|
// XParseColor rgb: and rgba: strings. You could use [HexColor], [XRGBColor],
|
|
// or [XRGBAColor] to format the color.
|
|
//
|
|
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
|
|
func SetBackgroundColor(s string) string {
|
|
return "\x1b]11;" + s + "\x07"
|
|
}
|
|
|
|
// RequestBackgroundColor is a sequence that requests the current default
|
|
// terminal background color.
|
|
//
|
|
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
|
|
const RequestBackgroundColor = "\x1b]11;?\x07"
|
|
|
|
// ResetBackgroundColor is a sequence that resets the default terminal
|
|
// background color.
|
|
//
|
|
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
|
|
const ResetBackgroundColor = "\x1b]111\x07"
|
|
|
|
// SetCursorColor returns a sequence that sets the terminal cursor color.
|
|
//
|
|
// OSC 12 ; color ST
|
|
// OSC 12 ; color BEL
|
|
//
|
|
// Where color is the encoded color number. Most terminals support hex,
|
|
// XParseColor rgb: and rgba: strings. You could use [HexColor], [XRGBColor],
|
|
// or [XRGBAColor] to format the color.
|
|
//
|
|
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
|
|
func SetCursorColor(s string) string {
|
|
return "\x1b]12;" + s + "\x07"
|
|
}
|
|
|
|
// RequestCursorColor is a sequence that requests the current terminal cursor
|
|
// color.
|
|
//
|
|
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
|
|
const RequestCursorColor = "\x1b]12;?\x07"
|
|
|
|
// ResetCursorColor is a sequence that resets the terminal cursor color.
|
|
//
|
|
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
|
|
const ResetCursorColor = "\x1b]112\x07"
|