mirror of
https://github.com/db9979/sshtermy.git
synced 2026-12-05 20:34:07 +01:00
- 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 Claude-Session: https://claude.ai/code/session_018i4GUk5KxaHH89KrFPon9n Co-authored-by: Claude <noreply@anthropic.com>
105 lines
2.8 KiB
Go
105 lines
2.8 KiB
Go
package ui
|
|
|
|
// Farbverläufe: Logo in der Kopfzeile von Akzent nach KI, Kopf- und
|
|
// Sitzungszeile mit einem sanften Schimmer der Umgebungsfarbe, der nach
|
|
// rechts in die normale Leiste übergeht. Aus bei Fensterstil „flach“ und im
|
|
// ruhigen Modus (gleiche Schalter wie die Schatten, frames.go).
|
|
|
|
import (
|
|
"image/color"
|
|
"strings"
|
|
|
|
"charm.land/lipgloss/v2"
|
|
"github.com/charmbracelet/x/ansi"
|
|
)
|
|
|
|
// gradientsOn: Verläufe zeichnen?
|
|
func gradientsOn() bool { return shadowsOn() }
|
|
|
|
// tintRun: Text mit dem Stil st, Hintergrund je Spalte aus bgAt (x zählt
|
|
// ab x0, damit mehrere Stücke einer Leiste einen Verlauf teilen). Gleiche
|
|
// Farben nebeneinander werden zusammengefasst.
|
|
func tintRun(s string, x0 int, st lipgloss.Style, bgAt func(x int) color.Color) string {
|
|
st = st.UnsetPadding()
|
|
// Hintergrund je Lauf als eigene Sequenz in einen einzigen Render: je Lauf
|
|
// ein eigenes Style.Render kostete in Kopf- und Sitzungszeile ~10 % eines Bildes.
|
|
var b strings.Builder
|
|
var runBg color.Color
|
|
runs, start := 0, true
|
|
for i, ch := range []rune(s) {
|
|
bg := bgAt(x0 + i)
|
|
if start || !sameColor(bg, runBg) {
|
|
runBg, start = bg, false
|
|
runs++
|
|
if bg == nil {
|
|
b.WriteString("\x1b[49m")
|
|
} else {
|
|
b.WriteString(ansi.Style{}.BackgroundColor(bg).String())
|
|
}
|
|
}
|
|
b.WriteRune(ch)
|
|
}
|
|
if runs <= 1 {
|
|
return st.Background(runBg).Render(s)
|
|
}
|
|
return st.Render(b.String())
|
|
}
|
|
|
|
// barTint: Hintergrund einer Leiste, links ein Hauch von tint, nach fade
|
|
// Spalten ganz base.
|
|
func barTint(tint, base color.Color, strength float64, fade int) func(x int) color.Color {
|
|
return func(x int) color.Color {
|
|
if tint == nil || !gradientsOn() {
|
|
return base
|
|
}
|
|
k := 1 - easeInOut(min(1, float64(x)/float64(max(1, fade))))
|
|
return mixColor(base, tint, strength*k)
|
|
}
|
|
}
|
|
|
|
// gradFg: Schrift im Verlauf fgA → fgB auf festem Hintergrund.
|
|
func gradFg(s string, fgA, fgB, bg color.Color, bold bool) string {
|
|
r := []rune(s)
|
|
var b strings.Builder
|
|
for i, ch := range r {
|
|
k := 0.0
|
|
if len(r) > 1 {
|
|
k = float64(i) / float64(len(r)-1)
|
|
}
|
|
st := lipgloss.NewStyle().Foreground(mixColor(fgA, fgB, k)).Bold(bold)
|
|
if bg != nil {
|
|
st = st.Background(bg)
|
|
}
|
|
b.WriteString(st.Render(string(ch)))
|
|
}
|
|
return b.String()
|
|
}
|
|
|
|
func sameColor(a, b color.Color) bool {
|
|
if a == nil || b == nil {
|
|
return a == b
|
|
}
|
|
return rgbOf(a) == rgbOf(b)
|
|
}
|
|
|
|
func easeInOut(t float64) float64 {
|
|
if t < 0.5 {
|
|
return 2 * t * t
|
|
}
|
|
return 1 - (-2*t+2)*(-2*t+2)/2
|
|
}
|
|
|
|
// logoChip: „>_ sshTermy“ als Schild, Hintergrund von Akzent nach KI.
|
|
func (a *App) logoChip(text string) string {
|
|
t := a.s.T
|
|
if !gradientsOn() {
|
|
return a.s.Logo.Render(text)
|
|
}
|
|
text = " " + text + " "
|
|
n := len([]rune(text))
|
|
to := mixColor(t.Accent, t.AI, 0.85)
|
|
return tintRun(text, 0, a.s.Logo, func(x int) color.Color {
|
|
return mixColor(t.Accent, to, float64(x)/float64(max(1, n-1)))
|
|
})
|
|
}
|