From 6344de0fda6fc8fe0b76007fb5ebbeb853adcf0b Mon Sep 17 00:00:00 2001 From: merefield Date: Wed, 26 Aug 2026 11:34:29 +0100 Subject: [PATCH] FIX: prioritize fuel gauge in short cards --- internal/ui/meters.go | 23 ++++++++++++---------- internal/ui/meters_test.go | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/internal/ui/meters.go b/internal/ui/meters.go index b89f4801..1ae67372 100644 --- a/internal/ui/meters.go +++ b/internal/ui/meters.go @@ -677,28 +677,31 @@ func renderFuelTank(width, used int, color imagecolor.Color, colors palette) str } func renderFuelTankSized(width, height, used int, color imagecolor.Color, colors palette) string { - height = max(height, 1) + if height <= 0 { + height = 6 + } remaining := 100 - used tankWidth := max(width-6, 1) available := int(math.Round(float64(tankWidth) * float64(remaining) / 100)) tank := lipgloss.NewStyle().Foreground(colors.primary).Render(strings.Repeat("▰", available)) + lipgloss.NewStyle().Foreground(colors.dim).Render(strings.Repeat("▱", tankWidth-available)) label := lipgloss.NewStyle().Bold(true).Foreground(color).Render(fmt.Sprintf("RANGE %3d%%", remaining)) - top := "╭" + strings.Repeat("─", tankWidth+2) + "╮" middle := "│ " + tank + " │" - bottom := "╰" + strings.Repeat("─", tankWidth+2) + "╯" + // The fuel itself is the primary signal. At constrained heights retain the + // tank row first, then restore the range readout, and only then the dim + // endpoint context. The enclosing meter layout independently drops the reset + // timeline and other telemetry before it reaches this one-row form. if height == 1 { - return lipgloss.PlaceHorizontal(width, lipgloss.Center, label) + return lipgloss.PlaceHorizontal(width, lipgloss.Center, middle) + } + if height == 2 { + return lipgloss.PlaceHorizontal(width, lipgloss.Center, middle+"\n"+label) } rows := make([]string, height) - rows[0] = colors.dimmed().Render(top) - rows[height-1] = colors.dimmed().Render(bottom) + rows[0] = colors.dimmed().Render("E" + strings.Repeat(" ", max(tankWidth, 1)) + "F") + rows[height-1] = label for row := 1; row < height-1; row++ { rows[row] = middle } - if height >= 4 { - rows[0] = colors.dimmed().Render("E" + strings.Repeat(" ", max(tankWidth, 1)) + "F") - rows[height-1] = label - } return lipgloss.PlaceHorizontal(width, lipgloss.Center, strings.Join(rows, "\n")) } diff --git a/internal/ui/meters_test.go b/internal/ui/meters_test.go index 8bbcdaa3..97ecfd01 100644 --- a/internal/ui/meters_test.go +++ b/internal/ui/meters_test.go @@ -243,6 +243,46 @@ func TestFuelTankIsReverseGaugeWithCorrectEndpoints(t *testing.T) { } } +func TestFuelTankPrioritizesFuelAtShortHeights(t *testing.T) { + colors := paletteFor(themeHacker) + for _, height := range []int{1, 2, 3} { + output := ansi.Strip(renderFuelTankSized(30, height, 40, colors.primary, colors)) + if got := lipgloss.Height(output); got != height { + t.Errorf("height %d rendered %d rows: %q", height, got, output) + } + if !strings.Contains(output, "▰") || !strings.Contains(output, "▱") { + t.Errorf("height %d omitted the fuel tank row: %q", height, output) + } + } + + minimum := ansi.Strip(renderFuelTankSized(30, 1, 40, colors.primary, colors)) + for _, secondary := range []string{"RANGE", "E", "F"} { + if strings.Contains(minimum, secondary) { + t.Errorf("one-row tank retained secondary label %q: %q", secondary, minimum) + } + } +} + +func TestShortFuelMeterDropsTelemetryBeforeTank(t *testing.T) { + colors := paletteFor(themeHacker) + duration := int64(60) + reset := time.Now().Add(30 * time.Minute).Unix() + meter := codex.Meter{ + Bucket: "codex", + Name: "1 HOUR", + Window: codex.Window{UsedPercent: 40, WindowDurationMins: &duration, ResetsAt: &reset}, + } + output := ansi.Strip(renderMeterArea(60, 3, meter, viewFuel, colors)) + if !strings.Contains(output, "▰") || !strings.Contains(output, "▱") { + t.Fatalf("minimum-height fuel meter omitted its tank:\n%s", output) + } + for _, secondary := range []string{"FREE", "USED", "RANGE", "RESET CYCLE", "RESET T-"} { + if strings.Contains(output, secondary) { + t.Errorf("minimum-height fuel meter retained secondary telemetry %q:\n%s", secondary, output) + } + } +} + func TestFuelTankStatsFollowReverseGaugeDirection(t *testing.T) { colors := paletteFor(themeHacker) meter := codex.Meter{