Revert "feat(tui): overhaul latency sparkline scaling, color, and layout"

This reverts commit 63926e2932.
This commit is contained in:
2026-06-04 19:37:20 -04:00
parent 63926e2932
commit e53077fe70
8 changed files with 35 additions and 349 deletions
+23 -64
View File
@@ -1,63 +1,15 @@
package tui
import (
"fmt"
"strings"
"time"
"github.com/charmbracelet/lipgloss"
)
var sparkChars = []rune{'▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'}
func parseHex(hex string) (r, g, b uint8) {
if len(hex) == 7 && hex[0] == '#' {
fmt.Sscanf(hex[1:], "%02x%02x%02x", &r, &g, &b)
}
return
}
func dimColor(hex string, brightness float64) lipgloss.Color {
r, g, b := parseHex(hex)
f := 0.3 + brightness*0.7
return lipgloss.Color(fmt.Sprintf("#%02x%02x%02x",
uint8(float64(r)*f),
uint8(float64(g)*f),
uint8(float64(b)*f),
))
}
func withBg(s lipgloss.Style, bg lipgloss.Color) lipgloss.Style {
if bg != "" {
return s.Background(bg)
}
return s
}
func latencyStyle(ms int64, bg lipgloss.Color) lipgloss.Style {
var hex string
var t float64
switch {
case ms < 200:
hex = sparkSuccess
t = float64(ms) / 200
case ms < 500:
hex = sparkWarning
t = float64(ms-200) / 300
default:
hex = sparkDanger
t = float64(ms-500) / 1500
if t > 1 {
t = 1
}
}
s := lipgloss.NewStyle().Foreground(dimColor(hex, t))
return withBg(s, bg)
}
func latencySparkline(latencies []time.Duration, statuses []bool, width int, bg lipgloss.Color) string {
func latencySparkline(latencies []time.Duration, statuses []bool, width int) string {
if len(latencies) == 0 {
return withBg(subtleStyle, bg).Render(strings.Repeat("·", width))
return subtleStyle.Render(strings.Repeat("·", width))
}
samples := latencies
@@ -78,12 +30,12 @@ func latencySparkline(latencies []time.Duration, statuses []bool, width int, bg
maxL = l
}
}
spread := maxL - minL
var sb strings.Builder
if remaining := width - len(samples); remaining > 0 {
sb.WriteString(withBg(subtleStyle, bg).Render(strings.Repeat("·", remaining)))
sb.WriteString(subtleStyle.Render(strings.Repeat("·", remaining)))
}
spread := maxL - minL
for i, l := range samples {
idx := 0
if spread > 0 {
@@ -95,17 +47,24 @@ func latencySparkline(latencies []time.Duration, statuses []bool, width int, bg
ch := string(sparkChars[idx])
isDown := i < len(sampledStatuses) && !sampledStatuses[i]
if isDown {
sb.WriteString(withBg(dangerStyle, bg).Render(ch))
sb.WriteString(dangerStyle.Render(ch))
} else {
sb.WriteString(latencyStyle(l.Milliseconds(), bg).Render(ch))
ms := l.Milliseconds()
if ms < 200 {
sb.WriteString(specialStyle.Render(ch))
} else if ms < 500 {
sb.WriteString(warnStyle.Render(ch))
} else {
sb.WriteString(dangerStyle.Render(ch))
}
}
}
return sb.String()
}
func heartbeatSparkline(statuses []bool, width int, bg lipgloss.Color) string {
func heartbeatSparkline(statuses []bool, width int) string {
if len(statuses) == 0 {
return withBg(subtleStyle, bg).Render(strings.Repeat("·", width))
return subtleStyle.Render(strings.Repeat("·", width))
}
samples := statuses
@@ -115,19 +74,19 @@ func heartbeatSparkline(statuses []bool, width int, bg lipgloss.Color) string {
var sb strings.Builder
if remaining := width - len(samples); remaining > 0 {
sb.WriteString(withBg(subtleStyle, bg).Render(strings.Repeat("·", remaining)))
sb.WriteString(subtleStyle.Render(strings.Repeat("·", remaining)))
}
for _, up := range samples {
if up {
sb.WriteString(withBg(specialStyle, bg).Render("▁"))
sb.WriteString(specialStyle.Render("▁"))
} else {
sb.WriteString(withBg(dangerStyle, bg).Render("█"))
sb.WriteString(dangerStyle.Render("█"))
}
}
return sb.String()
}
func (m Model) groupSparkline(groupID int, width int, bg lipgloss.Color) string {
func (m Model) groupSparkline(groupID int, width int) string {
allSites := m.engine.GetAllSites()
var childStatuses [][]bool
for _, s := range allSites {
@@ -140,7 +99,7 @@ func (m Model) groupSparkline(groupID int, width int, bg lipgloss.Color) string
}
if len(childStatuses) == 0 {
return withBg(subtleStyle, bg).Render(strings.Repeat("·", width))
return subtleStyle.Render(strings.Repeat("·", width))
}
maxLen := 0
@@ -168,13 +127,13 @@ func (m Model) groupSparkline(groupID int, width int, bg lipgloss.Color) string
var sb strings.Builder
if remaining := width - len(aggregated); remaining > 0 {
sb.WriteString(withBg(subtleStyle, bg).Render(strings.Repeat("·", remaining)))
sb.WriteString(subtleStyle.Render(strings.Repeat("·", remaining)))
}
for _, up := range aggregated {
if up {
sb.WriteString(withBg(subtleStyle, bg).Render("·"))
sb.WriteString(specialStyle.Render(""))
} else {
sb.WriteString(withBg(dangerStyle, bg).Render("•"))
sb.WriteString(dangerStyle.Render("•"))
}
}
return sb.String()