Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions internal/ui/meters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
40 changes: 40 additions & 0 deletions internal/ui/meters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down