diff --git a/pkg/tui/render/meter.go b/pkg/tui/render/meter.go index d6a46b6..0594ac5 100644 --- a/pkg/tui/render/meter.go +++ b/pkg/tui/render/meter.go @@ -86,9 +86,14 @@ func GradientMeter(frac float64, width int, stops []string, empty lipgloss.Style // SegmentMeter renders a btop-style segmented meter: discrete square cells, // filled portion swept through a color gradient, remainder in the track -// style (dark squares): +// style: // // ■■■■■■■■■■■■□□□□□ +// +// The filled cells use a solid glyph (■) and the track uses a hollow one (□) +// so the fill fraction stays legible even when color is unavailable (piped +// output, NO_COLOR, --once frames pasted into an issue). Encoding the fill in +// color alone made every bar look full-width in monochrome. func SegmentMeter(frac float64, width int, stops []string, track lipgloss.Style) string { if width <= 0 { return "" @@ -110,7 +115,7 @@ func SegmentMeter(frac float64, width int, stops []string, track lipgloss.Style) b.WriteString(styles[i].Render("■")) } if width-filled > 0 { - b.WriteString(track.Render(strings.Repeat("■", width-filled))) + b.WriteString(track.Render(strings.Repeat("□", width-filled))) } return b.String() } diff --git a/pkg/tui/render/render_test.go b/pkg/tui/render/render_test.go index 6038034..0b7125a 100644 --- a/pkg/tui/render/render_test.go +++ b/pkg/tui/render/render_test.go @@ -149,6 +149,29 @@ func TestMeterWidth(t *testing.T) { } } +// TestSegmentMeterLegibleWithoutColor guards the bargauge bug where the filled +// and track cells used the same glyph, so the fill fraction was carried by +// color alone and every bar looked full-width in monochrome output. +func TestSegmentMeterLegibleWithoutColor(t *testing.T) { + plain := lipgloss.NewStyle() // no color, as when ANSI is stripped + const width = 20 + for _, tc := range []struct { + frac float64 + wantFilled int + }{ + {0, 0}, {0.02, 0}, {0.5, 10}, {0.875, 18}, {1, 20}, + } { + out := SegmentMeter(tc.frac, width, []string{"#0f0", "#0f0"}, plain) + if got := lipgloss.Width(out); got != width { + t.Errorf("frac %v: width %d, want %d", tc.frac, got, width) + } + filled := strings.Count(out, "■") + if filled != tc.wantFilled { + t.Errorf("frac %v: filled ■ = %d, want %d (bar carries no width info)", tc.frac, filled, tc.wantFilled) + } + } +} + func TestFormatCompact(t *testing.T) { tests := []struct { in float64