fix(tui): add ANSI-16 color fallbacks for SSH terminals

Theme colors now use lipgloss.CompleteColor with hand-picked ANSI-16
values instead of raw hex. Prevents algorithmic degradation from
collapsing dark backgrounds into indistinguishable ANSI colors over
SSH. Backgrounds fall through to terminal default in 16-color mode;
semantic colors map to distinct ANSI indices (green/yellow/red/blue/
cyan/magenta). TrueColor rendering is unchanged.
This commit is contained in:
2026-06-17 18:20:15 -04:00
parent d50a5159d4
commit 974c4b61ea
6 changed files with 160 additions and 138 deletions
+19 -17
View File
@@ -5,10 +5,12 @@ import (
"testing"
"time"
"unicode/utf8"
"github.com/charmbracelet/lipgloss"
)
func TestLatencySparkline_Empty(t *testing.T) {
got := styledModel.latencySparkline(nil, nil, 10, "")
got := styledModel.latencySparkline(nil, nil, 10, nil)
if !strings.Contains(got, "··········") {
t.Errorf("empty sparkline should be dots, got %q", got)
}
@@ -17,7 +19,7 @@ func TestLatencySparkline_Empty(t *testing.T) {
func TestLatencySparkline_SingleValue(t *testing.T) {
latencies := []time.Duration{100 * time.Millisecond}
statuses := []bool{true}
got := styledModel.latencySparkline(latencies, statuses, 5, "")
got := styledModel.latencySparkline(latencies, statuses, 5, nil)
if len(got) == 0 {
t.Error("sparkline should not be empty")
}
@@ -33,7 +35,7 @@ func TestLatencySparkline_WidthTruncation(t *testing.T) {
latencies[i] = time.Duration(i*50) * time.Millisecond
statuses[i] = true
}
got := styledModel.latencySparkline(latencies, statuses, 5, "")
got := styledModel.latencySparkline(latencies, statuses, 5, nil)
if len(got) == 0 {
t.Error("sparkline should not be empty")
}
@@ -45,7 +47,7 @@ func TestLatencySparkline_WidthTruncation(t *testing.T) {
func TestLatencySparkline_RelativeHeight(t *testing.T) {
latencies := []time.Duration{10 * time.Millisecond, 50 * time.Millisecond, 10 * time.Millisecond}
statuses := []bool{true, true, true}
out := stripANSI(styledModel.latencySparkline(latencies, statuses, 3, ""))
out := stripANSI(styledModel.latencySparkline(latencies, statuses, 3, nil))
runes := []rune(out)
if len(runes) < 3 {
t.Fatalf("expected 3 runes, got %d", len(runes))
@@ -57,14 +59,14 @@ func TestLatencySparkline_RelativeHeight(t *testing.T) {
func TestLatencyStyle_BandsProduceDifferentColors(t *testing.T) {
st := newStyles(themeFlexokiDark)
st.sparkSuccess = "#00ff00"
st.sparkWarning = "#ffff00"
st.sparkDanger = "#ff0000"
st.sparkSuccess = lipgloss.Color("#00ff00")
st.sparkWarning = lipgloss.Color("#ffff00")
st.sparkDanger = lipgloss.Color("#ff0000")
m := Model{st: st}
green := m.latencyStyle(50, "")
yellow := m.latencyStyle(300, "")
red := m.latencyStyle(800, "")
green := m.latencyStyle(50, nil)
yellow := m.latencyStyle(300, nil)
red := m.latencyStyle(800, nil)
gfg := green.GetForeground()
yfg := yellow.GetForeground()
@@ -77,11 +79,11 @@ func TestLatencyStyle_BandsProduceDifferentColors(t *testing.T) {
func TestLatencyStyle_BrightnessVariesWithinBand(t *testing.T) {
st := newStyles(themeFlexokiDark)
st.sparkSuccess = "#00ff00"
st.sparkSuccess = lipgloss.Color("#00ff00")
m := Model{st: st}
dim := m.latencyStyle(10, "")
bright := m.latencyStyle(190, "")
dim := m.latencyStyle(10, nil)
bright := m.latencyStyle(190, nil)
if dim.GetForeground() == bright.GetForeground() {
t.Error("10ms and 190ms should have different brightness within green band")
@@ -91,7 +93,7 @@ func TestLatencyStyle_BrightnessVariesWithinBand(t *testing.T) {
func TestLatencySparkline_OutputWidth(t *testing.T) {
latencies := []time.Duration{100 * time.Millisecond, 200 * time.Millisecond, 300 * time.Millisecond}
statuses := []bool{true, true, true}
got := styledModel.latencySparkline(latencies, statuses, 5, "")
got := styledModel.latencySparkline(latencies, statuses, 5, nil)
count := utf8.RuneCountInString(stripANSI(got))
if count != 5 {
t.Errorf("expected 5 rune-width output, got %d from %q", count, got)
@@ -116,7 +118,7 @@ func stripANSI(s string) string {
}
func TestHeartbeatSparkline_Empty(t *testing.T) {
got := styledModel.heartbeatSparkline(nil, 10, "")
got := styledModel.heartbeatSparkline(nil, 10, nil)
if !strings.Contains(got, "··········") {
t.Errorf("empty heartbeat should be dots, got %q", got)
}
@@ -124,7 +126,7 @@ func TestHeartbeatSparkline_Empty(t *testing.T) {
func TestHeartbeatSparkline_Mixed(t *testing.T) {
statuses := []bool{true, false, true, true, false}
got := styledModel.heartbeatSparkline(statuses, 5, "")
got := styledModel.heartbeatSparkline(statuses, 5, nil)
if len(got) == 0 {
t.Error("heartbeat sparkline should not be empty")
}
@@ -132,7 +134,7 @@ func TestHeartbeatSparkline_Mixed(t *testing.T) {
func TestHeartbeatSparkline_PaddedWidth(t *testing.T) {
statuses := []bool{true, true}
got := styledModel.heartbeatSparkline(statuses, 5, "")
got := styledModel.heartbeatSparkline(statuses, 5, nil)
if !strings.Contains(got, "···") {
t.Errorf("should have dot padding for width > data, got %q", got)
}