diff --git a/README.md b/README.md index 2a8016bf..ecc9ec8b 100644 --- a/README.md +++ b/README.md @@ -303,7 +303,7 @@ codexometer --codex /path/to/codex The responsive top rail below the account status selects Quota, Monitor, or Benchmark by mouse, `Tab`, or `Shift+Tab`. Quota adds a second rail for Bars, -Pie, Consumption Pace, and Fuel Tank; select these with the mouse or cycle them +Consumption Pace, Pie, and Fuel Tank; select these with the mouse or cycle them with `v`. Codexometer remembers the selected Quota view when you leave and return. Both rails condense automatically as the terminal narrows. The footer presents the remaining actions as clickable buttons, including View diff --git a/internal/ui/benchmark.go b/internal/ui/benchmark.go index 5b933b4d..68eff751 100644 --- a/internal/ui/benchmark.go +++ b/internal/ui/benchmark.go @@ -902,7 +902,7 @@ func benchmarkSegmentButtonAt(localX int, segments []benchmarkControlSegment) fo } func (m Model) benchmarkHeaderAt(x, y int) (benchmarkSortColumn, bool) { - if m.meterStyle != styleBenchmark || x < 0 || y < 0 { + if m.meterView != viewBenchmark || x < 0 || y < 0 { return benchmarkSortNone, false } dashboard := m.dashboardLayout() diff --git a/internal/ui/benchmark_test.go b/internal/ui/benchmark_test.go index c8184076..a88a643e 100644 --- a/internal/ui/benchmark_test.go +++ b/internal/ui/benchmark_test.go @@ -60,7 +60,7 @@ func (f benchmarkStubFetcher) RunBenchmarkSuite(ctx context.Context, tasks []cod func TestBenchmarkViewRendersResponsiveResultsTable(t *testing.T) { model := Model{ - width: 100, height: 30, meterStyle: styleBenchmark, + width: 100, height: 30, meterView: viewBenchmark, benchmarkState: benchmarkFinished, benchmarkResults: []codex.BenchmarkResult{ {TaskName: "MERGE RANGES", Model: "gpt-5.6-sol", DisplayName: "GPT-5.6 Sol", Effort: "high", Correct: true, Duration: 12500 * time.Millisecond, Usage: codex.BenchmarkUsage{TotalTokens: 4321}, UsageKnown: true, CostKnown: true, CostUSD: 0.0412}, @@ -132,7 +132,7 @@ func TestVeryShortBenchmarkAreaExposesNoHiddenMouseTargets(t *testing.T) { for _, height := range []int{8, 9, 10} { model := Model{ snapshot: codex.DemoSnapshot(), width: 40, height: height, - meterStyle: styleBenchmark, + meterView: viewBenchmark, } dashboard := model.dashboardLayout() if dashboard.meterHeight >= 3 { @@ -173,7 +173,7 @@ func TestBenchmarkHotkeyRunsSuiteAndCollectsEvents(t *testing.T) { model := New(fetcher, time.Minute) model.snapshot = codex.DemoSnapshot() model.loading = false - model.meterStyle = styleBenchmark + model.meterView = viewBenchmark updated, command := model.Update(key('b')) model = updated.(Model) @@ -214,7 +214,7 @@ func TestBenchmarkButtonSupportsHoverAndClick(t *testing.T) { model.snapshot = codex.DemoSnapshot() model.loading = false model.width, model.height = 100, 30 - model.meterStyle = styleBenchmark + model.meterView = viewBenchmark x, y := benchmarkControlCoordinates(t, model, footerButtonBenchmarkSelected) mouse := tea.MouseMsg{X: x, Y: y, Action: tea.MouseActionMotion} updated, command := model.Update(mouse) @@ -250,7 +250,7 @@ func TestBenchmarkTableClipsOlderRows(t *testing.T) { } func TestBenchmarkPageKeysAndMouseWheelScrollResults(t *testing.T) { - model := Model{width: 90, height: 28, meterStyle: styleBenchmark, benchmarkState: benchmarkFinished} + model := Model{width: 90, height: 28, meterView: viewBenchmark, benchmarkState: benchmarkFinished} for index := 0; index < 30; index++ { model.benchmarkResults = append(model.benchmarkResults, codex.BenchmarkResult{DisplayName: "Model", Effort: "low"}) } @@ -273,7 +273,7 @@ func TestBenchmarkPageKeysAndMouseWheelScrollResults(t *testing.T) { func TestBenchmarkHeadingButtonsSortAndReverse(t *testing.T) { model := Model{ - width: 100, height: 30, meterStyle: styleBenchmark, benchmarkState: benchmarkFinished, + width: 100, height: 30, meterView: viewBenchmark, benchmarkState: benchmarkFinished, benchmarkResults: []codex.BenchmarkResult{ {DisplayName: "Zulu", Effort: "low", Duration: 2 * time.Second, Usage: codex.BenchmarkUsage{TotalTokens: 200}}, {DisplayName: "Alpha", Effort: "high", Correct: true, Duration: time.Second, Usage: codex.BenchmarkUsage{TotalTokens: 100}}, @@ -321,7 +321,7 @@ func TestBenchmarkRenderedClickSurfacesMatchHitTestingAcrossSizes(t *testing.T) t.Run(fmt.Sprintf("%dx%d", size.width, size.height), func(t *testing.T) { model := Model{ snapshot: codex.DemoSnapshot(), width: size.width, height: size.height, - meterStyle: styleBenchmark, benchmarkCombinations: 3, + meterView: viewBenchmark, benchmarkCombinations: 3, } dashboard := model.dashboardLayout() geometry := layoutBenchmarkArea(dashboard.contentWidth, dashboard.meterHeight) @@ -563,7 +563,7 @@ func TestBenchmarkTaskSelectorRunAllGuardAndExactTurnCount(t *testing.T) { model.snapshot = codex.DemoSnapshot() model.loading = false model.width, model.height = 100, 30 - model.meterStyle = styleBenchmark + model.meterView = viewBenchmark model.benchmarkCombinations = 33 updated, _ := model.Update(tea.KeyMsg{Type: tea.KeyRight}) @@ -617,7 +617,7 @@ func TestBenchmarkSelectorAnchorsButtonsToLongestTaskName(t *testing.T) { } } - clickable := Model{snapshot: codex.DemoSnapshot(), width: 100, height: 30, meterStyle: styleBenchmark} + clickable := Model{snapshot: codex.DemoSnapshot(), width: 100, height: 30, meterView: viewBenchmark} nextX, nextY := benchmarkControlCoordinates(t, clickable, footerButtonBenchmarkNext) for range clickable.benchmarkTasks() { clickable.selectBenchmarkTask(1) @@ -633,7 +633,7 @@ func TestBenchmarkRunAllLaunchesUnifiedCatalog(t *testing.T) { model := New(fetcher, time.Minute) model.snapshot = codex.DemoSnapshot() model.loading = false - model.meterStyle = styleBenchmark + model.meterView = viewBenchmark model.benchmarkCombinations = 1 model, _ = model.activateFooterButton(footerButtonBenchmarkAll) @@ -681,7 +681,7 @@ func TestBenchmarkRunAllAvailabilityRequiresTasksAndCombinations(t *testing.T) { func TestBenchmarkPassFailFilterButtonsAndHotkey(t *testing.T) { model := Model{ - width: 100, height: 30, meterStyle: styleBenchmark, benchmarkState: benchmarkFinished, + width: 100, height: 30, meterView: viewBenchmark, benchmarkState: benchmarkFinished, benchmarkResults: []codex.BenchmarkResult{ {DisplayName: "Passing", TaskName: "LRU CACHE", Correct: true}, {DisplayName: "Failing", TaskName: "SHORTEST PATH", Correct: false}, @@ -706,7 +706,7 @@ func TestBenchmarkPassFailFilterButtonsAndHotkey(t *testing.T) { func TestBenchmarkRankWeightButtonsAndHotkeyRecomputeImmediately(t *testing.T) { model := Model{ - width: 100, height: 30, snapshot: codex.DemoSnapshot(), meterStyle: styleBenchmark, + width: 100, height: 30, snapshot: codex.DemoSnapshot(), meterView: viewBenchmark, benchmarkRankMode: benchmarkRankBalanced, benchmarkResults: []codex.BenchmarkResult{ {Model: "cheap", DisplayName: "Cheap", Effort: "low", Correct: true, Duration: 30 * time.Second, CostKnown: true, CostUSD: 0.01}, diff --git a/internal/ui/meters.go b/internal/ui/meters.go index 97a61dfa..edc83480 100644 --- a/internal/ui/meters.go +++ b/internal/ui/meters.go @@ -12,21 +12,21 @@ import ( "github.com/merefield/codexometer/internal/codex" ) -func usesMeterGrid(style meterStyleID) bool { - switch style { - case styleBars, stylePie, styleConsumptionPace, styleFuel: +func usesMeterGrid(view meterViewID) bool { + switch view { + case viewBars, viewPie, viewConsumptionPace, viewFuel: return true default: return false } } -func renderMeterGrid(width, height int, meters []codex.Meter, style meterStyleID, colors palette) string { +func renderMeterGrid(width, height int, meters []codex.Meter, view meterViewID, colors palette) string { if len(meters) == 0 { return "" } const columnGap = 1 - columns := meterGridColumns(width, height, len(meters), style) + columns := meterGridColumns(width, height, len(meters), view) rows := (len(meters) + columns - 1) / columns rowGap := 1 // A framed meter needs at least its title, body, and bottom border. Drop the @@ -49,7 +49,7 @@ func renderMeterGrid(width, height int, meters []codex.Meter, style meterStyleID pieces = append(pieces, strings.Repeat(" ", columnGap)) } if meterIndex < len(meters) { - pieces = append(pieces, renderMeterArea(columnWidths[column], rowHeight, meters[meterIndex], style, colors)) + pieces = append(pieces, renderMeterArea(columnWidths[column], rowHeight, meters[meterIndex], view, colors)) } else { pieces = append(pieces, strings.Repeat(" ", columnWidths[column])) } @@ -63,13 +63,13 @@ func renderMeterGrid(width, height int, meters []codex.Meter, style meterStyleID return grid } -func meterGridColumns(width, height, meterCount int, style meterStyleID) int { - if style == styleBars || style == styleConsumptionPace || style == styleFuel { +func meterGridColumns(width, height, meterCount int, view meterViewID) int { + if view == viewBars || view == viewConsumptionPace || view == viewFuel { return 1 } minimumColumns := 1 maximumColumns := meterCount - if isRadialStyle(style) && meterCount > 1 { + if isRadialView(view) && meterCount > 1 { minimumColumns = 2 // Below this width the circular canvas and title both become ambiguous. // Retain at least two columns, then add more only when each card remains @@ -87,8 +87,8 @@ func meterGridColumns(width, height, meterCount int, style meterStyleID) int { visualChrome := 6 visualHeight := max(cellHeight-visualChrome, 1) detail := innerWidth * visualHeight - switch style { - case stylePie: + switch view { + case viewPie: canvasWidth, canvasHeight := radialCanvasSize(innerWidth, visualHeight, 11) detail = canvasWidth * canvasHeight } @@ -100,8 +100,8 @@ func meterGridColumns(width, height, meterCount int, style meterStyleID) int { return bestColumns } -func isRadialStyle(style meterStyleID) bool { - return style == stylePie +func isRadialView(view meterViewID) bool { + return view == viewPie } func distributeSpace(total, parts int) []int { @@ -117,11 +117,11 @@ func distributeSpace(total, parts int) []int { return sizes } -func renderMeter(width int, meter codex.Meter, style meterStyleID, colors palette) string { - return renderMeterArea(width, 0, meter, style, colors) +func renderMeter(width int, meter codex.Meter, view meterViewID, colors palette) string { + return renderMeterArea(width, 0, meter, view, colors) } -func renderMeterArea(width, height int, meter codex.Meter, style meterStyleID, colors palette) string { +func renderMeterArea(width, height int, meter codex.Meter, view meterViewID, colors palette) string { used := min(max(meter.Window.UsedPercent, 0), 100) free := 100 - used color := meterColor(used, colors) @@ -129,17 +129,17 @@ func renderMeterArea(width, height int, meter codex.Meter, style meterStyleID, c usedText := lipgloss.NewStyle().Bold(true).Foreground(color).Render(fmt.Sprintf("USED %3d%%", used)) freeText := colors.dimmed().Render(fmt.Sprintf("FREE %3d%%", free)) - if style == styleFuel { + if view == viewFuel { usedText = colors.dimmed().Render(fmt.Sprintf("USED %3d%%", used)) freeText = lipgloss.NewStyle().Bold(true).Foreground(colors.primary).Render(fmt.Sprintf("FREE %3d%%", free)) } gap := max(innerWidth-lipgloss.Width(usedText)-lipgloss.Width(freeText), 1) stats := usedText + strings.Repeat(" ", gap) + freeText - if style == styleFuel { + if view == viewFuel { stats = freeText + strings.Repeat(" ", gap) + usedText } if lipgloss.Width(stats) > innerWidth { - if style == styleFuel { + if view == viewFuel { stats = freeText } else { stats = usedText @@ -166,13 +166,13 @@ func renderMeterArea(width, height int, meter codex.Meter, style meterStyleID, c visualHeight = max(bodyHeight-chromeHeight, 1) } now := time.Now() - visual := renderVisualizationSized(innerWidth, visualHeight, used, style, color, colors) - if style == styleConsumptionPace { + visual := renderVisualizationSized(innerWidth, visualHeight, used, view, color, colors) + if view == viewConsumptionPace { visual = renderConsumptionPaceMeterSized(innerWidth, visualHeight, meter.Window, now, colors) } gaugeWidth := min(max(lipgloss.Width(visual), 1), innerWidth) resetGauge := renderResetGauge(innerWidth, gaugeWidth, meter.Window, now, reset, color, colors) - if style == styleFuel { + if view == viewFuel { gaugeWidth = max(innerWidth-6, 1) resetGauge = renderReverseResetGauge(innerWidth, gaugeWidth, meter.Window, now, reset, color, colors) } @@ -290,19 +290,19 @@ func meterColor(used int, colors palette) lipgloss.Color { return colors.primary } -func renderVisualization(width, used int, style meterStyleID, color lipgloss.Color, colors palette) string { - return renderVisualizationSized(width, 0, used, style, color, colors) +func renderVisualization(width, used int, view meterViewID, color lipgloss.Color, colors palette) string { + return renderVisualizationSized(width, 0, used, view, color, colors) } -func renderVisualizationSized(width, height, used int, style meterStyleID, color lipgloss.Color, colors palette) string { - switch style { - case stylePie: +func renderVisualizationSized(width, height, used int, view meterViewID, color lipgloss.Color, colors palette) string { + switch view { + case viewPie: return renderPieSized(width, height, used, color, colors) - case styleConsumptionPace: + case viewConsumptionPace: return renderConsumptionPaceSized(width, height, 0, false, colors) - case styleFuel: + case viewFuel: return renderFuelTankSized(width, height, used, color, colors) - case styleBars: + case viewBars: return renderClassicBarSized(width, height, used, color, colors) default: return renderClassicBarSized(width, height, used, color, colors) diff --git a/internal/ui/meters_test.go b/internal/ui/meters_test.go index a8d3633e..db2a5a83 100644 --- a/internal/ui/meters_test.go +++ b/internal/ui/meters_test.go @@ -12,41 +12,41 @@ import ( "github.com/merefield/codexometer/internal/codex" ) -var quotaMeterStyles = []meterStyleID{styleBars, stylePie, styleConsumptionPace, styleFuel} +var quotaMeterViews = []meterViewID{viewBars, viewConsumptionPace, viewPie, viewFuel} -func TestEveryMeterStyleHasDistinctiveOutput(t *testing.T) { +func TestEveryMeterViewHasDistinctiveOutput(t *testing.T) { colors := paletteFor(themeHacker) tests := []struct { - style meterStyleID - want string + view meterViewID + want string }{ - {styleBars, "█"}, - {stylePie, "BRAILLE PIE"}, - {styleConsumptionPace, "PACE DATA UNAVAILABLE"}, - {styleFuel, "RANGE"}, + {viewBars, "█"}, + {viewPie, "BRAILLE PIE"}, + {viewConsumptionPace, "PACE DATA UNAVAILABLE"}, + {viewFuel, "RANGE"}, } for _, test := range tests { - output := renderVisualization(60, 62, test.style, colors.primary, colors) + output := renderVisualization(60, 62, test.view, colors.primary, colors) if !strings.Contains(output, test.want) { - t.Errorf("style %s output did not contain %q", test.style.name(), test.want) + t.Errorf("view %s output did not contain %q", test.view.name(), test.want) } } } -func TestEveryMeterStyleUsesAllocatedRectangle(t *testing.T) { +func TestEveryMeterViewUsesAllocatedRectangle(t *testing.T) { colors := paletteFor(themeHacker) - for _, style := range quotaMeterStyles { - output := renderVisualizationSized(50, 12, 62, style, colors.primary, colors) + for _, view := range quotaMeterViews { + output := renderVisualizationSized(50, 12, 62, view, colors.primary, colors) if got := lipgloss.Width(output); got > 50 { - t.Errorf("%s width = %d, exceeds allocation 50", style.name(), got) + t.Errorf("%s width = %d, exceeds allocation 50", view.name(), got) } if got := lipgloss.Height(output); got != 12 { - t.Errorf("%s height = %d, want allocation 12", style.name(), got) + t.Errorf("%s height = %d, want allocation 12", view.name(), got) } } } -func TestEveryStyleIncludesResetCycleGauge(t *testing.T) { +func TestEveryViewIncludesResetCycleGauge(t *testing.T) { colors := paletteFor(themeHacker) duration := int64(60) reset := time.Now().Add(30 * time.Minute).Unix() @@ -55,24 +55,24 @@ func TestEveryStyleIncludesResetCycleGauge(t *testing.T) { Name: "1 HOUR", Window: codex.Window{UsedPercent: 40, WindowDurationMins: &duration, ResetsAt: &reset}, } - for _, style := range quotaMeterStyles { - output := ansi.Strip(renderMeterArea(80, 18, meter, style, colors)) + for _, view := range quotaMeterViews { + output := ansi.Strip(renderMeterArea(80, 18, meter, view, colors)) if !strings.Contains(output, "RESET CYCLE 50%") { - t.Errorf("%s missing reset-cycle comparison gauge:\n%s", style.name(), output) + t.Errorf("%s missing reset-cycle comparison gauge:\n%s", view.name(), output) } - visual := renderVisualizationSized(50, 10, 40, style, colors.primary, colors) + visual := renderVisualizationSized(50, 10, 40, view, colors.primary, colors) visualWidth := min(lipgloss.Width(visual), 50) gauge := ansi.Strip(renderResetGauge(50, visualWidth, meter.Window, time.Unix(reset, 0).Add(-30*time.Minute), "RESET T-00:30:00", colors.primary, colors)) lines := strings.Split(gauge, "\n") if len(lines) != 2 { - t.Errorf("%s reset gauge used %d lines, want label and bar: %q", style.name(), len(lines), gauge) + t.Errorf("%s reset gauge used %d lines, want label and bar: %q", view.name(), len(lines), gauge) continue } if strings.ContainsAny(lines[0], "█░") { - t.Errorf("%s reset label shares its line with the bar: %q", style.name(), lines[0]) + t.Errorf("%s reset label shares its line with the bar: %q", view.name(), lines[0]) } if got := lipgloss.Width(strings.TrimRight(lines[1], " ")); got != visualWidth { - t.Errorf("%s reset bar width = %d, want main display width %d", style.name(), got, visualWidth) + t.Errorf("%s reset bar width = %d, want main display width %d", view.name(), got, visualWidth) } } } @@ -192,7 +192,7 @@ func TestMonthlyCreditMeterShowsDetailsWithoutInventingCycleProgress(t *testing. Details: "8000 OF 25000 CREDITS USED", Window: codex.Window{UsedPercent: 32, ResetsAt: &reset}, } - output := ansi.Strip(renderMeterArea(80, 18, meter, styleBars, colors)) + output := ansi.Strip(renderMeterArea(80, 18, meter, viewBars, colors)) for _, want := range []string{"MONTHLY CREDIT LIMIT", "USED 32%", "8000 OF 25000 CREDITS USED", "CYCLE START UNAVAILABLE", "RESET T-"} { if !strings.Contains(output, want) { t.Errorf("monthly meter missing %q:\n%s", want, output) @@ -233,7 +233,7 @@ func TestFuelTankStatsFollowReverseGaugeDirection(t *testing.T) { Name: "1 HOUR", Window: codex.Window{UsedPercent: 25}, } - rendered := renderMeter(60, meter, styleFuel, colors) + rendered := renderMeter(60, meter, viewFuel, colors) wantFree := lipgloss.NewStyle().Bold(true).Foreground(colors.primary).Render("FREE 75%") wantUsed := colors.dimmed().Render("USED 25%") if !strings.Contains(rendered, wantFree) || !strings.Contains(rendered, wantUsed) { @@ -307,8 +307,8 @@ func TestRadialGraphicsUseLargeCircularCanvases(t *testing.T) { func TestRadialGraphicsScaleToAllocatedRectangle(t *testing.T) { colors := paletteFor(themeBlueSteel) - small := renderVisualizationSized(42, 9, 62, stylePie, colors.primary, colors) - large := renderVisualizationSized(70, 20, 62, stylePie, colors.primary, colors) + small := renderVisualizationSized(42, 9, 62, viewPie, colors.primary, colors) + large := renderVisualizationSized(70, 20, 62, viewPie, colors.primary, colors) if got := lipgloss.Width(small); got != 42 { t.Errorf("pie small width = %d, want 42", got) } diff --git a/internal/ui/model.go b/internal/ui/model.go index 1b0394d2..0c259ab6 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -42,15 +42,15 @@ type Model struct { nextRefresh time.Time phase int theme themeID - meterStyle meterStyleID - quotaMeterStyle meterStyleID + meterView meterViewID + quotaMeterView meterViewID hoveredMainTab mainTabID mainTabHovered bool - hoveredStyle meterStyleID - styleHovered bool - flashedStyle meterStyleID - styleFlashing bool - styleSequence uint64 + hoveredView meterViewID + viewHovered bool + flashedView meterViewID + viewFlashing bool + viewSequence uint64 hoveredButton footerButtonID flashedButton footerButtonID flashSequence uint64 @@ -196,8 +196,8 @@ type footerButtonFlashExpiredMsg struct { sequence uint64 } -type styleTabFlashExpiredMsg struct { - style meterStyleID +type viewTabFlashExpiredMsg struct { + view meterViewID sequence uint64 } @@ -319,11 +319,11 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { case "t": return m.pressFooterButton(footerButtonTheme) case "s": - if m.meterStyle == styleMonitor { + if m.meterView == viewMonitor { return m.pressFooterButton(footerButtonMonitorGo) } case "v": - if m.meterStyle.isQuota() { + if m.meterView.isQuota() { return m.pressFooterButton(footerButtonView) } case "tab": @@ -335,50 +335,50 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { case "q": return m.pressFooterButton(footerButtonQuit) case "b": - if m.meterStyle == styleBenchmark { + if m.meterView == viewBenchmark { return m.pressFooterButton(footerButtonBenchmarkSelected) } case "a": - if m.meterStyle == styleBenchmark { + if m.meterView == viewBenchmark { return m.pressFooterButton(footerButtonBenchmarkAll) } case "left", "[": - if m.meterStyle == styleBenchmark { + if m.meterView == viewBenchmark { return m.pressFooterButton(footerButtonBenchmarkPrevious) } case "right", "]": - if m.meterStyle == styleBenchmark { + if m.meterView == viewBenchmark { return m.pressFooterButton(footerButtonBenchmarkNext) } case "f": - if m.meterStyle == styleBenchmark { + if m.meterView == viewBenchmark { m.setBenchmarkFilter((m.benchmarkFilter + 1) % 3) return m, nil } case "w": - if m.meterStyle == styleBenchmark { + if m.meterView == viewBenchmark { return m.pressFooterButton(benchmarkRankButton(m.benchmarkRankMode.next())) } case "pgup": - if m.meterStyle == styleBenchmark { + if m.meterView == viewBenchmark { m.scrollBenchmarkPage(1) return m, nil } - if m.meterStyle == styleMonitor { + if m.meterView == viewMonitor { m.scrollMonitorPage(-1) return m, nil } case "pgdown": - if m.meterStyle == styleBenchmark { + if m.meterView == viewBenchmark { m.scrollBenchmarkPage(-1) return m, nil } - if m.meterStyle == styleMonitor { + if m.meterView == viewMonitor { m.scrollMonitorPage(1) return m, nil } case "p": - if m.meterStyle == styleMonitor { + if m.meterView == viewMonitor { return m.pressFooterButton(footerButtonMonitorStop) } } @@ -386,7 +386,7 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { if tab, ok := m.mainTabAt(message.X, message.Y); ok { m.mainTabHovered = true m.hoveredMainTab = tab - m.styleHovered = false + m.viewHovered = false m.hoveredButton = footerButtonNone if message.Button == tea.MouseButtonLeft && message.Action == tea.MouseActionPress { return m.pressMainTab(tab) @@ -394,16 +394,16 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { return m, nil } m.mainTabHovered = false - if style, ok := m.quotaStyleTabAt(message.X, message.Y); ok { - m.styleHovered = true - m.hoveredStyle = style + if view, ok := m.quotaViewTabAt(message.X, message.Y); ok { + m.viewHovered = true + m.hoveredView = view m.hoveredButton = footerButtonNone if message.Button == tea.MouseButtonLeft && message.Action == tea.MouseActionPress { - return m.pressStyleTab(style) + return m.pressViewTab(view) } return m, nil } - m.styleHovered = false + m.viewHovered = false if column, ok := m.benchmarkHeaderAt(message.X, message.Y); ok { m.benchmarkSortHovered = true m.benchmarkHoveredSort = column @@ -414,7 +414,7 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { return m, nil } m.benchmarkSortHovered = false - if m.meterStyle == styleMonitor { + if m.meterView == viewMonitor { switch message.Button { case tea.MouseButtonWheelUp: m.scrollMonitorRows(-1) @@ -424,7 +424,7 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { return m, nil } } - if m.meterStyle == styleBenchmark { + if m.meterView == viewBenchmark { switch message.Button { case tea.MouseButtonWheelUp: m.scrollBenchmarkRows(3) @@ -518,9 +518,9 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { if message.sequence == m.flashSequence && message.button == m.flashedButton { m.flashedButton = footerButtonNone } - case styleTabFlashExpiredMsg: - if message.sequence == m.styleSequence && message.style == m.flashedStyle { - m.styleFlashing = false + case viewTabFlashExpiredMsg: + if message.sequence == m.viewSequence && message.view == m.flashedView { + m.viewFlashing = false } case benchmarkEventMsg: if !message.ok { @@ -570,23 +570,23 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { return m, nil } -func (m Model) pressStyleTab(style meterStyleID) (tea.Model, tea.Cmd) { - if style < styleBars || style >= styleCount { +func (m Model) pressViewTab(view meterViewID) (tea.Model, tea.Cmd) { + if view < viewBars || view >= viewCount { return m, nil } - m.meterStyle = style - if style.isQuota() { - m.quotaMeterStyle = style + m.meterView = view + if view.isQuota() { + m.quotaMeterView = view } m.persistPreferences() - m.styleSequence++ - m.flashedStyle = style - m.styleFlashing = true - sequence := m.styleSequence + m.viewSequence++ + m.flashedView = view + m.viewFlashing = true + sequence := m.viewSequence commands := []tea.Cmd{tea.Tick(footerButtonFlashDuration, func(time.Time) tea.Msg { - return styleTabFlashExpiredMsg{style: style, sequence: sequence} + return viewTabFlashExpiredMsg{view: view, sequence: sequence} })} - if style == styleBenchmark && m.benchmarkRunner != nil && m.benchmarkCombinations == 0 && !m.benchmarkPlanning { + if view == viewBenchmark && m.benchmarkRunner != nil && m.benchmarkCombinations == 0 && !m.benchmarkPlanning { m.benchmarkPlanning = true commands = append(commands, planBenchmark(m.benchmarkRunner)) } @@ -618,9 +618,9 @@ func (m Model) activateFooterButton(button footerButtonID) (Model, tea.Cmd) { m.theme = m.theme.next() m.persistPreferences() case footerButtonView: - if m.meterStyle.isQuota() { - m.meterStyle = m.meterStyle.nextQuota() - m.quotaMeterStyle = m.meterStyle + if m.meterView.isQuota() { + m.meterView = m.meterView.nextQuota() + m.quotaMeterView = m.meterView m.persistPreferences() } case footerButtonRefresh: @@ -629,7 +629,7 @@ func (m Model) activateFooterButton(button footerButtonID) (Model, tea.Cmd) { return m, m.fetch() } case footerButtonMonitorGo: - if m.meterStyle == styleMonitor && (m.monitorState == monitorIdle || m.monitorState == monitorStopped) { + if m.meterView == viewMonitor && (m.monitorState == monitorIdle || m.monitorState == monitorStopped) { m.monitorState = monitorStarting m.monitorStartedAt = time.Time{} m.monitorStoppedAt = time.Time{} @@ -647,7 +647,7 @@ func (m Model) activateFooterButton(button footerButtonID) (Model, tea.Cmd) { return m, m.monitorFetch(monitorFetchStart, m.monitorRequest) } case footerButtonMonitorStop: - if m.meterStyle == styleMonitor && m.monitorState == monitorRunning { + if m.meterView == viewMonitor && m.monitorState == monitorRunning { m.monitorState = monitorStopping m.monitorRequest++ m.monitorFetchActive = true @@ -662,7 +662,7 @@ func (m Model) activateFooterButton(button footerButtonID) (Model, tea.Cmd) { m.selectBenchmarkTask(1) } case footerButtonBenchmarkSelected: - if m.meterStyle == styleBenchmark && m.benchmarkState != benchmarkRunning { + if m.meterView == viewBenchmark && m.benchmarkState != benchmarkRunning { m.benchmarkAllArmed = false tasks := m.benchmarkTasks() if len(tasks) > 0 { @@ -671,7 +671,7 @@ func (m Model) activateFooterButton(button footerButtonID) (Model, tea.Cmd) { } case footerButtonBenchmarkAll: tasks := m.benchmarkTasks() - if m.meterStyle == styleBenchmark && benchmarkRunAllAvailable(m.benchmarkState == benchmarkRunning, m.benchmarkCombinations, len(tasks)) { + if m.meterView == viewBenchmark && benchmarkRunAllAvailable(m.benchmarkState == benchmarkRunning, m.benchmarkCombinations, len(tasks)) { if !m.benchmarkAllArmed { m.benchmarkAllArmed = true m.benchmarkConfirmSequence++ @@ -708,12 +708,12 @@ func (m Model) footerButtonAt(x, y int) footerButtonID { if m.loading && len(m.snapshot.Meters()) == 0 { return footerButtonNone } - if m.meterStyle == styleMonitor { + if m.meterView == viewMonitor { if button := m.monitorButtonAt(x, y); button != footerButtonNone { return button } } - if m.meterStyle == styleBenchmark { + if m.meterView == viewBenchmark { if button := m.benchmarkButtonAt(x, y); button != footerButtonNone { return button } @@ -723,7 +723,7 @@ func (m Model) footerButtonAt(x, y int) footerButtonID { return footerButtonNone } localX := x - 2 - buttons, separator := footerButtonLayoutWithTheme(layout.contentWidth, paletteFor(m.theme).name, m.meterStyle.isQuota()) + buttons, separator := footerButtonLayoutWithTheme(layout.contentWidth, paletteFor(m.theme).name, m.meterView.isQuota()) buttonX := 0 for _, button := range buttons { if localX >= buttonX && localX < buttonX+len(button.label) { @@ -761,7 +761,7 @@ func (m Model) dashboardLayout() dashboardGeometry { } statusHeight := 1 tabsHeight := 1 - if m.meterStyle.isQuota() { + if m.meterView.isQuota() { tabsHeight++ } const framedErrorHeight = 3 @@ -774,7 +774,7 @@ func (m Model) dashboardLayout() dashboardGeometry { if len(meters) == 0 { extraHeight += framedErrorHeight } - if (m.meterStyle == styleBars || m.meterStyle == styleConsumptionPace || m.meterStyle == styleFuel) && len(meters) > 0 { + if (m.meterView == viewBars || m.meterView == viewConsumptionPace || m.meterView == viewFuel) && len(meters) > 0 { minimumMeterHeight := len(meters) * 3 meterHeightWithSpacer := contentHeight - headerHeight - statusHeight - tabsHeight - extraHeight - footerHeight meterHeightWithoutSpacer := meterHeightWithSpacer + statusHeight @@ -784,13 +784,13 @@ func (m Model) dashboardLayout() dashboardGeometry { } tabsY := 1 + headerHeight + statusHeight quotaTabsY := -1 - if m.meterStyle.isQuota() { + if m.meterView.isQuota() { quotaTabsY = tabsY + 1 } meterY := tabsY + tabsHeight + extraHeight meterHeight := max(contentHeight-headerHeight-statusHeight-tabsHeight-extraHeight-footerHeight, 1) footerY := meterY - if m.meterStyle == styleMonitor || m.meterStyle == styleBenchmark || len(m.snapshot.Meters()) > 0 { + if m.meterView == viewMonitor || m.meterView == viewBenchmark || len(m.snapshot.Meters()) > 0 { footerY += meterHeight } return dashboardGeometry{ diff --git a/internal/ui/model_test.go b/internal/ui/model_test.go index c3da6417..3edcfd7e 100644 --- a/internal/ui/model_test.go +++ b/internal/ui/model_test.go @@ -67,17 +67,17 @@ func TestThemeHotkeyCyclesAndWraps(t *testing.T) { func TestTabCyclesMainTabsAndShiftTabMovesBack(t *testing.T) { model := New(nil, time.Minute) - for _, want := range []meterStyleID{styleMonitor, styleBenchmark, styleBars} { + for _, want := range []meterViewID{viewMonitor, viewBenchmark, viewBars} { updated, _ := model.Update(tea.KeyMsg{Type: tea.KeyTab}) model = updated.(Model) - if model.meterStyle != want { - t.Fatalf("got meter style %d, want %d", model.meterStyle, want) + if model.meterView != want { + t.Fatalf("got meter view %d, want %d", model.meterView, want) } } updated, _ := model.Update(tea.KeyMsg{Type: tea.KeyShiftTab}) model = updated.(Model) - if model.meterStyle != styleBenchmark { - t.Fatalf("reverse main-tab navigation got %d, want %d", model.meterStyle, styleBenchmark) + if model.meterView != viewBenchmark { + t.Fatalf("reverse main-tab navigation got %d, want %d", model.meterView, viewBenchmark) } } @@ -248,8 +248,8 @@ func TestFooterButtonsSupportHoverAndMouseClicks(t *testing.T) { updated, command = model.Update(footerMouseMessage(t, model, footerButtonView, tea.MouseActionPress)) model = updated.(Model) - if command == nil || model.meterStyle != stylePie || model.flashedButton != footerButtonView { - t.Fatalf("view click selected view=%d flash=%d", model.meterStyle, model.flashedButton) + if command == nil || model.meterView != viewConsumptionPace || model.flashedButton != footerButtonView { + t.Fatalf("view click selected view=%d flash=%d", model.meterView, model.flashedButton) } updated, command = model.Update(footerMouseMessage(t, model, footerButtonRefresh, tea.MouseActionPress)) @@ -266,15 +266,15 @@ func TestFooterButtonsSupportHoverAndMouseClicks(t *testing.T) { } func TestViewFooterButtonOnlyExistsOnQuota(t *testing.T) { - for _, style := range []meterStyleID{styleMonitor, styleBenchmark} { - model := Model{snapshot: codex.DemoSnapshot(), width: 100, height: 30, meterStyle: style} + for _, view := range []meterViewID{viewMonitor, viewBenchmark} { + model := Model{snapshot: codex.DemoSnapshot(), width: 100, height: 30, meterView: view} if _, ok := footerButtonByID(model, footerButtonView); ok { - t.Fatalf("%s footer exposed the View button", style.name()) + t.Fatalf("%s footer exposed the View button", view.name()) } for y := 0; y < model.height; y++ { for x := 0; x < model.width; x++ { if got := model.footerButtonAt(x, y); got == footerButtonView { - t.Fatalf("%s exposed hidden View hit target at %d,%d", style.name(), x, y) + t.Fatalf("%s exposed hidden View hit target at %d,%d", view.name(), x, y) } } } @@ -287,14 +287,14 @@ func TestFooterHitGeometryMatchesRenderedButtonsAcrossSizes(t *testing.T) { width, height int empty bool withError bool - style meterStyleID + view meterViewID }{ {name: "compact", width: 40, height: 24}, {name: "standard", width: 80, height: 24}, {name: "large error", width: 120, height: 40, withError: true}, {name: "empty quota", width: 80, height: 24, empty: true}, - {name: "empty monitor", width: 80, height: 24, empty: true, style: styleMonitor}, - {name: "benchmark", width: 100, height: 30, style: styleBenchmark}, + {name: "empty monitor", width: 80, height: 24, empty: true, view: viewMonitor}, + {name: "benchmark", width: 100, height: 30, view: viewBenchmark}, } { t.Run(test.name, func(t *testing.T) { model := New(stubFetcher{snapshot: codex.DemoSnapshot()}, time.Minute) @@ -304,12 +304,12 @@ func TestFooterHitGeometryMatchesRenderedButtonsAcrossSizes(t *testing.T) { model.loading = false model.width = test.width model.height = test.height - model.meterStyle = test.style + model.meterView = test.view if test.withError { model.err = errors.New("stale quota signal") } layout := model.dashboardLayout() - buttons, _ := footerButtonLayoutWithTheme(layout.contentWidth, paletteFor(model.theme).name, model.meterStyle.isQuota()) + buttons, _ := footerButtonLayoutWithTheme(layout.contentWidth, paletteFor(model.theme).name, model.meterView.isQuota()) for _, visible := range buttons { id := visible.id mouse := footerMouseMessage(t, model, id, tea.MouseActionMotion) @@ -451,7 +451,7 @@ func footerMouseMessage(t *testing.T, model Model, id footerButtonID, action tea } func footerButtonByID(model Model, id footerButtonID) (footerButton, bool) { - buttons, _ := footerButtonLayoutWithTheme(model.contentWidth(), paletteFor(model.theme).name, model.meterStyle.isQuota()) + buttons, _ := footerButtonLayoutWithTheme(model.contentWidth(), paletteFor(model.theme).name, model.meterView.isQuota()) for _, button := range buttons { if button.id == id { return button, true diff --git a/internal/ui/monitor_test.go b/internal/ui/monitor_test.go index d88f73dc..e429b257 100644 --- a/internal/ui/monitor_test.go +++ b/internal/ui/monitor_test.go @@ -21,7 +21,7 @@ func TestMonitorGoSampleAndStopLifecycle(t *testing.T) { model := New(stubLiveFetcher{stubFetcher: stubFetcher{snapshot: codex.DemoSnapshot()}}, time.Minute) model.snapshot = codex.DemoSnapshot() model.loading = false - model.meterStyle = styleMonitor + model.meterView = viewMonitor updated, command := model.Update(key('s')) model = updated.(Model) @@ -87,7 +87,7 @@ func TestMonitorGoSampleAndStopLifecycle(t *testing.T) { func TestMonitorTickSamplesOnlyWhileRunningAndIgnoresStaleResults(t *testing.T) { model := New(stubLiveFetcher{stubFetcher: stubFetcher{snapshot: codex.DemoSnapshot()}}, time.Minute) - model.meterStyle = styleMonitor + model.meterView = viewMonitor updated, command := model.Update(secondMsg(time.Now())) model = updated.(Model) if command == nil || model.monitorFetchActive { @@ -537,7 +537,7 @@ func TestMonitorSessionRowsStayInsideResponsiveRectangle(t *testing.T) { func TestMonitorSessionPagesRespondToKeyboardAndMouse(t *testing.T) { model := Model{ - meterStyle: styleMonitor, width: 84, height: 24, + meterView: viewMonitor, width: 84, height: 24, monitorSessionData: []monitorSession{ {id: "a", displayed: true}, {id: "b", displayed: true}, {id: "c", displayed: true}, {id: "d", displayed: true}, @@ -562,7 +562,7 @@ func TestMonitorSessionPagesRespondToKeyboardAndMouse(t *testing.T) { } func TestMonitorSurfacesUnavailableAndFailedFinalUsage(t *testing.T) { - model := Model{meterStyle: styleMonitor, monitorState: monitorStarting, monitorRequest: 1} + model := Model{meterView: viewMonitor, monitorState: monitorStarting, monitorRequest: 1} updated, _ := model.Update(monitorFetchedMsg{ kind: monitorFetchStart, sequence: 1, err: errors.New("local telemetry unavailable"), at: time.Now(), }) @@ -614,7 +614,7 @@ func TestMonitorViewIsResponsiveAndGraphAutoScales(t *testing.T) { for _, size := range []struct{ width, height int }{{80, 24}, {120, 40}, {200, 60}} { model := Model{ snapshot: codex.DemoSnapshot(), width: size.width, height: size.height, - meterStyle: styleMonitor, monitorState: monitorRunning, + meterView: viewMonitor, monitorState: monitorRunning, monitorBaseline: 1_000, monitorLatest: 7_250, monitorStartedAt: time.Now().Add(-time.Minute), monitorSamples: []monitorSample{{intervalTokens: 250}, {intervalTokens: 6_000}}, @@ -682,7 +682,7 @@ func TestMonitorSessionProminentlyDistinguishesAttentionReason(t *testing.T) { func TestMonitorLargeButtonsAreClickableAcrossTheirBoxes(t *testing.T) { model := Model{ snapshot: codex.DemoSnapshot(), width: 100, height: 36, - meterStyle: styleMonitor, monitorState: monitorIdle, + meterView: viewMonitor, monitorState: monitorIdle, } colors := paletteFor(model.theme) dashboard := model.dashboardLayout() @@ -743,7 +743,7 @@ func TestMonitorButtonBoxesMatchEnabledHitSurfacesAcrossSizes(t *testing.T) { for _, state := range []monitorState{monitorIdle, monitorRunning} { model := Model{ snapshot: codex.DemoSnapshot(), width: size.width, height: size.height, - meterStyle: styleMonitor, monitorState: state, + meterView: viewMonitor, monitorState: state, } dashboard := model.dashboardLayout() geometry := layoutMonitorArea(dashboard.contentWidth, dashboard.meterHeight) diff --git a/internal/ui/preferences.go b/internal/ui/preferences.go index 26fbc478..1f9297ba 100644 --- a/internal/ui/preferences.go +++ b/internal/ui/preferences.go @@ -78,9 +78,9 @@ func (m *Model) applyPreferences(preferences Preferences) { if theme, ok := themePreferenceIDs[preferences.Theme]; ok { m.theme = theme } - if style, ok := quotaViewPreferenceIDs[preferences.QuotaView]; ok { - m.meterStyle = style - m.quotaMeterStyle = style + if view, ok := quotaViewPreferenceIDs[preferences.QuotaView]; ok { + m.meterView = view + m.quotaMeterView = view } if filter, ok := benchmarkFilterPreferenceIDs[preferences.BenchmarkFilter]; ok { m.benchmarkFilter = filter @@ -96,7 +96,7 @@ func (m Model) persistPreferences() { } _ = m.preferenceStore.Save(Preferences{ Theme: themePreferenceNames[m.theme], - QuotaView: quotaViewPreferenceNames[m.selectedQuotaStyle()], + QuotaView: quotaViewPreferenceNames[m.selectedQuotaView()], BenchmarkFilter: benchmarkFilterPreferenceNames[m.benchmarkFilter], BenchmarkRank: benchmarkRankPreferenceNames[m.benchmarkRankMode], }) @@ -117,14 +117,14 @@ func reverseThemePreferences(values map[themeID]string) map[string]themeID { return reversed } -var quotaViewPreferenceNames = map[meterStyleID]string{ - styleBars: "bars", stylePie: "pie", styleConsumptionPace: "consumption-pace", styleFuel: "fuel-tank", +var quotaViewPreferenceNames = map[meterViewID]string{ + viewBars: "bars", viewPie: "pie", viewConsumptionPace: "consumption-pace", viewFuel: "fuel-tank", } -var quotaViewPreferenceIDs = reverseStylePreferences(quotaViewPreferenceNames) +var quotaViewPreferenceIDs = reverseViewPreferences(quotaViewPreferenceNames) -func reverseStylePreferences(values map[meterStyleID]string) map[string]meterStyleID { - reversed := make(map[string]meterStyleID, len(values)) +func reverseViewPreferences(values map[meterViewID]string) map[string]meterViewID { + reversed := make(map[string]meterViewID, len(values)) for id, value := range values { reversed[value] = id } diff --git a/internal/ui/preferences_test.go b/internal/ui/preferences_test.go index d2309a94..e356c6d3 100644 --- a/internal/ui/preferences_test.go +++ b/internal/ui/preferences_test.go @@ -29,7 +29,7 @@ func TestPreferencesRestoreAndPersistPresentationChoices(t *testing.T) { Theme: "nightshade", QuotaView: "fuel-tank", BenchmarkFilter: "fail", BenchmarkRank: "cost", }} model := NewWithPreferences(nil, time.Minute, store) - if model.theme != themeNightshade || model.meterStyle != styleFuel || model.quotaMeterStyle != styleFuel || + if model.theme != themeNightshade || model.meterView != viewFuel || model.quotaMeterView != viewFuel || model.benchmarkFilter != benchmarkFilterFail || model.benchmarkRankMode != benchmarkRankCost { t.Fatalf("preferences were not restored: %#v", model) } @@ -55,7 +55,7 @@ func TestInvalidOrUnreadablePreferencesKeepSafeDefaults(t *testing.T) { {loadErr: errors.New("broken config")}, } { model := NewWithPreferences(nil, time.Minute, store) - if model.theme != themeHacker || model.meterStyle != styleBars || model.benchmarkFilter != benchmarkFilterAll || + if model.theme != themeHacker || model.meterView != viewBars || model.benchmarkFilter != benchmarkFilterAll || model.benchmarkRankMode != benchmarkRankBalanced { t.Fatalf("invalid preferences changed defaults: %#v", model) } diff --git a/internal/ui/quota_api_eq.go b/internal/ui/quota_api_eq.go index 5b19ceef..da4b50b7 100644 --- a/internal/ui/quota_api_eq.go +++ b/internal/ui/quota_api_eq.go @@ -257,7 +257,7 @@ func (m Model) quotaMetersWithInsights(width int) []codex.Meter { meters := m.snapshot.Meters() lineWidth := max(width-4, 1) if len(meters) > 0 { - columns := meterGridColumns(width, m.dashboardLayout().meterHeight, len(meters), m.meterStyle) + columns := meterGridColumns(width, m.dashboardLayout().meterHeight, len(meters), m.meterView) lineWidth = max((width-(columns-1))/columns-4, 1) } for index := range meters { diff --git a/internal/ui/quota_api_eq_test.go b/internal/ui/quota_api_eq_test.go index 24c2b5a3..3b326bf6 100644 --- a/internal/ui/quota_api_eq_test.go +++ b/internal/ui/quota_api_eq_test.go @@ -225,11 +225,11 @@ func TestEveryQuotaViewDisplaysResponsiveAPIEqReadout(t *testing.T) { Key: key, CapacityUSD: 20, LowUSD: 18, HighUSD: 22, DeltaPercent: 10, ObservedAtUnix: now.Unix(), PricingRetrievedOn: codex.StandardAPIPricingRetrievedOn, }} - for _, style := range quotaStyleOrder { - model.meterStyle, model.quotaMeterStyle = style, style - view := ansi.Strip(model.View()) - if !strings.Contains(view, "API-EQ") || !strings.Contains(view, "100%") { - t.Errorf("%s omitted API-EQ readout:\n%s", style.name(), view) + for _, view := range quotaViewOrder { + model.meterView, model.quotaMeterView = view, view + rendered := ansi.Strip(model.View()) + if !strings.Contains(rendered, "API-EQ") || !strings.Contains(rendered, "100%") { + t.Errorf("%s omitted API-EQ readout:\n%s", view.name(), rendered) } } model.width = 48 diff --git a/internal/ui/tabs.go b/internal/ui/tabs.go index 0ac06789..5ae54f63 100644 --- a/internal/ui/tabs.go +++ b/internal/ui/tabs.go @@ -31,8 +31,8 @@ type mainTab struct { width int } -type styleTab struct { - style meterStyleID +type viewTab struct { + view meterViewID label string x int width int @@ -91,69 +91,69 @@ func mainTabLayout(width int, recording bool) ([]mainTab, string) { return tabs, separator } -func quotaStyleTabLayout(width int) ([]styleTab, string) { +func quotaViewTabLayout(width int) ([]viewTab, string) { labels, separator := responsiveTabLabels(width, [][]string{ - {"╭ BARS ╮", "╭ PIE ╮", "╭ CONSUMPTION PACE ╮", "╭ FUEL TANK ╮"}, - {"╭BAR╮", "╭PIE╮", "╭PACE╮", "╭FUEL╮"}, - {"[B]", "[P]", "[C]", "[F]"}, - {"B", "P", "C", "F"}, + {"╭ BARS ╮", "╭ CONSUMPTION PACE ╮", "╭ PIE ╮", "╭ FUEL TANK ╮"}, + {"╭BAR╮", "╭PACE╮", "╭PIE╮", "╭FUEL╮"}, + {"[B]", "[C]", "[P]", "[F]"}, + {"B", "C", "P", "F"}, }) - tabs := make([]styleTab, 0, len(quotaStyleOrder)) + tabs := make([]viewTab, 0, len(quotaViewOrder)) x := 0 for index, label := range labels { tabWidth := lipgloss.Width(label) if x+tabWidth > width { break } - tabs = append(tabs, styleTab{style: quotaStyleOrder[index], label: label, x: x, width: tabWidth}) + tabs = append(tabs, viewTab{view: quotaViewOrder[index], label: label, x: x, width: tabWidth}) x += tabWidth + len(separator) } return tabs, separator } func (m Model) currentMainTab() mainTabID { - switch m.meterStyle { - case styleMonitor: + switch m.meterView { + case viewMonitor: return mainTabMonitor - case styleBenchmark: + case viewBenchmark: return mainTabBenchmark default: return mainTabQuota } } -func (m Model) selectedQuotaStyle() meterStyleID { - if m.meterStyle.isQuota() { - return m.meterStyle +func (m Model) selectedQuotaView() meterViewID { + if m.meterView.isQuota() { + return m.meterView } - if m.quotaMeterStyle.isQuota() { - return m.quotaMeterStyle + if m.quotaMeterView.isQuota() { + return m.quotaMeterView } - return styleBars + return viewBars } func (m Model) pressMainTab(tab mainTabID) (tea.Model, tea.Cmd) { - if m.meterStyle.isQuota() { - m.quotaMeterStyle = m.meterStyle + if m.meterView.isQuota() { + m.quotaMeterView = m.meterView } switch tab { case mainTabQuota: - return m.pressStyleTab(m.selectedQuotaStyle()) + return m.pressViewTab(m.selectedQuotaView()) case mainTabMonitor: - return m.pressStyleTab(styleMonitor) + return m.pressViewTab(viewMonitor) case mainTabBenchmark: - return m.pressStyleTab(styleBenchmark) + return m.pressViewTab(viewBenchmark) default: return m, nil } } -func mainTabForStyle(style meterStyleID) mainTabID { - switch style { - case styleMonitor: +func mainTabForView(view meterViewID) mainTabID { + switch view { + case viewMonitor: return mainTabMonitor - case styleBenchmark: + case viewBenchmark: return mainTabBenchmark default: return mainTabQuota @@ -168,9 +168,9 @@ func (m Model) renderMainTabs(width int, colors palette) string { for _, tab := range tabs { active := tab.tab == m.currentMainTab() hovered := m.mainTabHovered && tab.tab == m.hoveredMainTab - flashed := m.styleFlashing && tab.tab == mainTabForStyle(m.flashedStyle) + flashed := m.viewFlashing && tab.tab == mainTabForView(m.flashedView) base, background := tabAppearance(active, hovered, flashed, colors) - parts = append(parts, renderStyleTabLabel(tab.label, base, background, recording && tab.tab == mainTabMonitor, m.phase, colors)) + parts = append(parts, renderViewTabLabel(tab.label, base, background, recording && tab.tab == mainTabMonitor, m.phase, colors)) used += tab.width } if len(parts) > 1 { @@ -179,14 +179,14 @@ func (m Model) renderMainTabs(width int, colors palette) string { return strings.Join(parts, colors.dimmed().Render(separator)) + strings.Repeat(" ", max(width-used, 0)) } -func (m Model) renderQuotaStyleTabs(width int, colors palette) string { - tabs, separator := quotaStyleTabLayout(width) +func (m Model) renderQuotaViewTabs(width int, colors palette) string { + tabs, separator := quotaViewTabLayout(width) parts := make([]string, 0, len(tabs)) used := 0 for _, tab := range tabs { - active := tab.style == m.meterStyle - hovered := m.styleHovered && tab.style == m.hoveredStyle - flashed := m.styleFlashing && tab.style == m.flashedStyle + active := tab.view == m.meterView + hovered := m.viewHovered && tab.view == m.hoveredView + flashed := m.viewFlashing && tab.view == m.flashedView base, _ := tabAppearance(active, hovered, flashed, colors) parts = append(parts, base.Render(tab.label)) used += tab.width @@ -215,7 +215,7 @@ func tabAppearance(active, hovered, flashed bool, colors palette) (lipgloss.Styl return lipgloss.NewStyle().Foreground(foreground).Background(background).Bold(bold), background } -func renderStyleTabLabel(label string, base lipgloss.Style, background lipgloss.Color, recording bool, phase int, colors palette) string { +func renderViewTabLabel(label string, base lipgloss.Style, background lipgloss.Color, recording bool, phase int, colors palette) string { if !recording || !strings.Contains(label, "●") { return base.Render(label) } @@ -250,20 +250,20 @@ func (m Model) mainTabAt(x, y int) (mainTabID, bool) { return mainTabQuota, false } -func (m Model) quotaStyleTabAt(x, y int) (meterStyleID, bool) { - if x < 0 || y < 0 || !m.meterStyle.isQuota() || (m.loading && len(m.snapshot.Meters()) == 0) { - return styleBars, false +func (m Model) quotaViewTabAt(x, y int) (meterViewID, bool) { + if x < 0 || y < 0 || !m.meterView.isQuota() || (m.loading && len(m.snapshot.Meters()) == 0) { + return viewBars, false } layout := m.dashboardLayout() if y != layout.quotaTabsY { - return styleBars, false + return viewBars, false } localX := x - 2 - tabs, _ := quotaStyleTabLayout(layout.contentWidth) + tabs, _ := quotaViewTabLayout(layout.contentWidth) for _, tab := range tabs { if localX >= tab.x && localX < tab.x+tab.width { - return tab.style, true + return tab.view, true } } - return styleBars, false + return viewBars, false } diff --git a/internal/ui/tabs_test.go b/internal/ui/tabs_test.go index aa74f1ad..c7f4fed7 100644 --- a/internal/ui/tabs_test.go +++ b/internal/ui/tabs_test.go @@ -41,7 +41,7 @@ func TestMainTabsChooseResponsiveLabels(t *testing.T) { } } -func TestQuotaStyleTabsChooseResponsiveLabels(t *testing.T) { +func TestQuotaViewTabsChooseResponsiveLabels(t *testing.T) { for _, test := range []struct { width int want string @@ -52,9 +52,9 @@ func TestQuotaStyleTabsChooseResponsiveLabels(t *testing.T) { {width: 4, want: "C"}, } { t.Run(test.want, func(t *testing.T) { - tabs, _ := quotaStyleTabLayout(test.width) - if len(tabs) != len(quotaStyleOrder) { - t.Fatalf("width %d displayed %d quota tabs, want %d", test.width, len(tabs), len(quotaStyleOrder)) + tabs, _ := quotaViewTabLayout(test.width) + if len(tabs) != len(quotaViewOrder) { + t.Fatalf("width %d displayed %d quota tabs, want %d", test.width, len(tabs), len(quotaViewOrder)) } var labels strings.Builder for _, tab := range tabs { @@ -66,6 +66,9 @@ func TestQuotaStyleTabsChooseResponsiveLabels(t *testing.T) { if !strings.Contains(labels.String(), test.want) { t.Fatalf("width %d labels %q do not contain %q", test.width, labels.String(), test.want) } + if len(tabs) >= 3 && (tabs[1].view != viewConsumptionPace || !strings.Contains(tabs[1].label, test.want) || tabs[2].view != viewPie) { + t.Fatalf("width %d tab order/labels do not match views: %#v", test.width, tabs) + } }) } } @@ -92,17 +95,17 @@ func TestMainTabsSupportHoverClickAndPulse(t *testing.T) { mouse.Action = tea.MouseActionPress updated, command = model.Update(mouse) model = updated.(Model) - if command == nil || model.meterStyle != styleMonitor || !model.styleFlashing || model.flashedStyle != styleMonitor { - t.Fatalf("monitor click did not select and pulse: style=%d flashing=%v", model.meterStyle, model.styleFlashing) + if command == nil || model.meterView != viewMonitor || !model.viewFlashing || model.flashedView != viewMonitor { + t.Fatalf("monitor click did not select and pulse: view=%d flashing=%v", model.meterView, model.viewFlashing) } } -func TestQuotaStyleTabsSupportHoverClickAndPulse(t *testing.T) { +func TestQuotaViewTabsSupportHoverClickAndPulse(t *testing.T) { model := New(stubFetcher{snapshot: codex.DemoSnapshot()}, time.Minute) model.snapshot = codex.DemoSnapshot() model.loading = false model.width, model.height = 100, 30 - tabs, _ := quotaStyleTabLayout(model.contentWidth()) + tabs, _ := quotaViewTabLayout(model.contentWidth()) target := tabs[1] mouse := tea.MouseMsg{ X: 2 + target.x + target.width/2, @@ -112,19 +115,19 @@ func TestQuotaStyleTabsSupportHoverClickAndPulse(t *testing.T) { } updated, command := model.Update(mouse) model = updated.(Model) - if command != nil || !model.styleHovered || model.hoveredStyle != stylePie { - t.Fatalf("pie hover was not recorded: hovered=%v style=%d", model.styleHovered, model.hoveredStyle) + if command != nil || !model.viewHovered || model.hoveredView != viewConsumptionPace { + t.Fatalf("consumption pace hover was not recorded: hovered=%v view=%d", model.viewHovered, model.hoveredView) } mouse.Action = tea.MouseActionPress updated, command = model.Update(mouse) model = updated.(Model) - if command == nil || model.meterStyle != stylePie || model.quotaMeterStyle != stylePie || !model.styleFlashing || model.flashedStyle != stylePie { - t.Fatalf("pie click did not select, remember, and pulse: style=%d remembered=%d flashing=%v", model.meterStyle, model.quotaMeterStyle, model.styleFlashing) + if command == nil || model.meterView != viewConsumptionPace || model.quotaMeterView != viewConsumptionPace || !model.viewFlashing || model.flashedView != viewConsumptionPace { + t.Fatalf("consumption pace click did not select, remember, and pulse: view=%d remembered=%d flashing=%v", model.meterView, model.quotaMeterView, model.viewFlashing) } - updated, _ = model.Update(styleTabFlashExpiredMsg{style: stylePie, sequence: model.styleSequence}) + updated, _ = model.Update(viewTabFlashExpiredMsg{view: viewConsumptionPace, sequence: model.viewSequence}) model = updated.(Model) - if model.styleFlashing { + if model.viewFlashing { t.Fatal("current tab pulse did not expire") } } @@ -141,10 +144,10 @@ func TestEveryRenderedTabCellIsClickableAcrossWidths(t *testing.T) { } } } - quotaTabs, _ := quotaStyleTabLayout(layout.contentWidth) + quotaTabs, _ := quotaViewTabLayout(layout.contentWidth) for _, tab := range quotaTabs { for offset := 0; offset < tab.width; offset++ { - if got, ok := model.quotaStyleTabAt(2+tab.x+offset, layout.quotaTabsY); !ok || got != tab.style { + if got, ok := model.quotaViewTabAt(2+tab.x+offset, layout.quotaTabsY); !ok || got != tab.view { t.Errorf("width %d quota tab %q cell %d hit (%d,%v)", width, tab.label, offset, got, ok) } } @@ -153,90 +156,90 @@ func TestEveryRenderedTabCellIsClickableAcrossWidths(t *testing.T) { } func TestQuotaStyleIsRememberedAcrossMainTabNavigation(t *testing.T) { - model := Model{meterStyle: stylePie} + model := Model{meterView: viewPie} updated, _ := model.Update(tea.KeyMsg{Type: tea.KeyTab}) model = updated.(Model) - if model.meterStyle != styleMonitor { - t.Fatalf("Tab selected %s, want Monitor", model.meterStyle.name()) + if model.meterView != viewMonitor { + t.Fatalf("Tab selected %s, want Monitor", model.meterView.name()) } updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyTab}) model = updated.(Model) - if model.meterStyle != styleBenchmark { - t.Fatalf("second Tab selected %s, want Benchmark", model.meterStyle.name()) + if model.meterView != viewBenchmark { + t.Fatalf("second Tab selected %s, want Benchmark", model.meterView.name()) } updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyTab}) model = updated.(Model) - if model.meterStyle != stylePie { - t.Fatalf("return to Quota selected %s, want remembered Pie", model.meterStyle.name()) + if model.meterView != viewPie { + t.Fatalf("return to Quota selected %s, want remembered Pie", model.meterView.name()) } updated, _ = model.Update(tea.KeyMsg{Type: tea.KeyShiftTab}) model = updated.(Model) - if model.meterStyle != styleBenchmark { - t.Fatalf("Shift+Tab selected %s, want Benchmark", model.meterStyle.name()) + if model.meterView != viewBenchmark { + t.Fatalf("Shift+Tab selected %s, want Benchmark", model.meterView.name()) } } func TestVSelectsQuotaViewAndSOnlyStartsMonitor(t *testing.T) { - model := Model{meterStyle: styleBars} - for _, want := range []meterStyleID{stylePie, styleConsumptionPace, styleFuel, styleBars} { + model := Model{meterView: viewBars} + for _, want := range []meterViewID{viewConsumptionPace, viewPie, viewFuel, viewBars} { updated, command := model.Update(key('v')) model = updated.(Model) - if command == nil || model.meterStyle != want || model.quotaMeterStyle != want || model.flashedButton != footerButtonView { - t.Fatalf("V selected view=%d remembered=%d flash=%d, want view=%d", model.meterStyle, model.quotaMeterStyle, model.flashedButton, want) + if command == nil || model.meterView != want || model.quotaMeterView != want || model.flashedButton != footerButtonView { + t.Fatalf("V selected view=%d remembered=%d flash=%d, want view=%d", model.meterView, model.quotaMeterView, model.flashedButton, want) } } sequence := model.flashSequence updated, command := model.Update(key('s')) model = updated.(Model) - if command != nil || model.meterStyle != styleBars || model.flashSequence != sequence { + if command != nil || model.meterView != viewBars || model.flashSequence != sequence { t.Fatal("S changed the Quota view") } - model = Model{meterStyle: styleMonitor, monitorState: monitorIdle} + model = Model{meterView: viewMonitor, monitorState: monitorIdle} updated, command = model.Update(key('s')) model = updated.(Model) if command == nil || model.monitorState != monitorStarting || model.flashedButton != footerButtonMonitorGo { t.Fatalf("Monitor S did not start: state=%d flash=%d", model.monitorState, model.flashedButton) } - model = Model{meterStyle: styleBenchmark} + model = Model{meterView: viewBenchmark} updated, command = model.Update(key('s')) model = updated.(Model) - if command != nil || model.meterStyle != styleBenchmark || model.flashedButton != footerButtonNone { + if command != nil || model.meterView != viewBenchmark || model.flashedButton != footerButtonNone { t.Fatal("S changed state in Benchmark") } } func TestQuotaSubTabsOnlyRenderAndHitTestWithinQuota(t *testing.T) { colors := paletteFor(themeHacker) - for _, style := range []meterStyleID{styleBars, styleMonitor, styleBenchmark} { - model := Model{snapshot: codex.DemoSnapshot(), width: 100, height: 30, meterStyle: style} + for _, view := range []meterViewID{viewBars, viewMonitor, viewBenchmark} { + model := Model{snapshot: codex.DemoSnapshot(), width: 100, height: 30, meterView: view} output := ansi.Strip(model.View()) layout := model.dashboardLayout() - if style.isQuota() { + if view.isQuota() { if layout.quotaTabsY < 0 || !strings.Contains(output, "CONSUMPTION PACE") { t.Fatalf("Quota did not render its sub-tab rail:\n%s", output) } continue } if layout.quotaTabsY != -1 || strings.Contains(output, "CONSUMPTION PACE") { - t.Fatalf("%s exposed Quota sub-tabs", style.name()) + t.Fatalf("%s exposed Quota sub-tabs", view.name()) } for y := 0; y < model.height; y++ { for x := 0; x < model.width; x++ { - if _, ok := model.quotaStyleTabAt(x, y); ok { - t.Fatalf("%s exposed hidden Quota sub-tab hit target at %d,%d", style.name(), x, y) + if _, ok := model.quotaViewTabAt(x, y); ok { + t.Fatalf("%s exposed hidden Quota sub-tab hit target at %d,%d", view.name(), x, y) } } } if lipgloss.Width(model.renderMainTabs(model.contentWidth(), colors)) != model.contentWidth() { - t.Fatalf("%s main tab rail did not fill available width", style.name()) + t.Fatalf("%s main tab rail did not fill available width", view.name()) } } } func TestMonitorMainTabShowsPulsingRecordingDotWhileQuotaIsActive(t *testing.T) { - model := Model{meterStyle: styleBars, monitorState: monitorRunning} + model := Model{meterView: viewBars, monitorState: monitorRunning} colors := paletteFor(themeHacker) model.phase = 0 bright := model.renderMainTabs(100, colors) diff --git a/internal/ui/theme.go b/internal/ui/theme.go index 07cf66e4..30f6b6e0 100644 --- a/internal/ui/theme.go +++ b/internal/ui/theme.go @@ -17,44 +17,44 @@ func (t themeID) next() themeID { return (t + 1) % themeCount } -type meterStyleID int +type meterViewID int const ( - styleBars meterStyleID = iota - styleMonitor - stylePie - styleConsumptionPace - styleFuel - styleBenchmark - styleCount + viewBars meterViewID = iota + viewMonitor + viewPie + viewConsumptionPace + viewFuel + viewBenchmark + viewCount ) -var quotaStyleOrder = [...]meterStyleID{ - styleBars, - stylePie, - styleConsumptionPace, - styleFuel, +var quotaViewOrder = [...]meterViewID{ + viewBars, + viewConsumptionPace, + viewPie, + viewFuel, } -func (s meterStyleID) isQuota() bool { - for _, style := range quotaStyleOrder { - if s == style { +func (s meterViewID) isQuota() bool { + for _, view := range quotaViewOrder { + if s == view { return true } } return false } -func (s meterStyleID) nextQuota() meterStyleID { - for index, style := range quotaStyleOrder { - if s == style { - return quotaStyleOrder[(index+1)%len(quotaStyleOrder)] +func (s meterViewID) nextQuota() meterViewID { + for index, view := range quotaViewOrder { + if s == view { + return quotaViewOrder[(index+1)%len(quotaViewOrder)] } } - return styleBars + return viewBars } -func (s meterStyleID) name() string { +func (s meterViewID) name() string { return [...]string{ "BARS", "MONITOR", diff --git a/internal/ui/view.go b/internal/ui/view.go index a5cb0818..1c0f69b4 100644 --- a/internal/ui/view.go +++ b/internal/ui/view.go @@ -30,15 +30,15 @@ func (m Model) View() string { parts = append(parts, strings.Repeat(" ", contentWidth)) } parts = append(parts, m.renderMainTabs(contentWidth, colors)) - if m.meterStyle.isQuota() { - parts = append(parts, m.renderQuotaStyleTabs(contentWidth, colors)) + if m.meterView.isQuota() { + parts = append(parts, m.renderQuotaViewTabs(contentWidth, colors)) } if m.err != nil { errorView := renderError(contentWidth, m.err, colors) parts = append(parts, errorView) } meters := m.snapshot.Meters() - if m.meterStyle.isQuota() { + if m.meterView.isQuota() { meters = m.quotaMetersWithInsights(contentWidth) } if len(meters) == 0 { @@ -46,14 +46,14 @@ func (m Model) View() string { parts = append(parts, emptyView) } footer := m.renderFooter(contentWidth, colors) - if m.meterStyle == styleMonitor { + if m.meterView == viewMonitor { parts = append(parts, m.renderMonitorArea(contentWidth, layout.meterHeight, colors).view) - } else if m.meterStyle == styleBenchmark { + } else if m.meterView == viewBenchmark { parts = append(parts, m.renderBenchmarkArea(contentWidth, layout.meterHeight, colors)) } else if len(meters) > 1 { - parts = append(parts, renderMeterGrid(contentWidth, layout.meterHeight, meters, m.meterStyle, colors)) + parts = append(parts, renderMeterGrid(contentWidth, layout.meterHeight, meters, m.meterView, colors)) } else if len(meters) == 1 { - parts = append(parts, renderMeterArea(contentWidth, layout.meterHeight, meters[0], m.meterStyle, colors)) + parts = append(parts, renderMeterArea(contentWidth, layout.meterHeight, meters[0], m.meterView, colors)) } parts = append(parts, footer) } @@ -154,10 +154,10 @@ func (m Model) renderFooter(width int, colors palette) string { } } status := colors.dimmed().Render(ansi.Truncate(left, width, "")) - if m.meterStyle == styleBenchmark || m.meterStyle.isQuota() { + if m.meterView == viewBenchmark || m.meterView.isQuota() { status = renderPricingFooter(status, width, colors) } - buttons, separator := footerButtonLayoutWithTheme(width, colors.name, m.meterStyle.isQuota()) + buttons, separator := footerButtonLayoutWithTheme(width, colors.name, m.meterView.isQuota()) controls := make([]string, 0, len(buttons)) for _, button := range buttons { controls = append(controls, footerButtonAppearance( diff --git a/internal/ui/view_test.go b/internal/ui/view_test.go index 39c7497d..2d913b5f 100644 --- a/internal/ui/view_test.go +++ b/internal/ui/view_test.go @@ -12,37 +12,37 @@ import ( "github.com/merefield/codexometer/internal/codex" ) -func TestViewRendersEveryThemeAndStyleWithinStandardTerminal(t *testing.T) { +func TestViewRendersEveryThemeAndViewWithinStandardTerminal(t *testing.T) { for theme := themeHacker; theme < themeCount; theme++ { - for style := styleBars; style < styleCount; style++ { + for view := viewBars; view < viewCount; view++ { model := Model{ snapshot: codex.DemoSnapshot(), width: 120, height: 52, nextRefresh: time.Now().Add(time.Minute), theme: theme, - meterStyle: style, + meterView: view, } output := ansi.Strip(model.View()) if !strings.Contains(output, paletteFor(theme).name) { t.Errorf("theme %d name missing from view", theme) } - if !strings.Contains(output, style.name()) { - t.Errorf("style %d name missing from view", style) + if !strings.Contains(output, view.name()) { + t.Errorf("view %d name missing from view", view) } - if style == styleMonitor { + if view == viewMonitor { if !strings.Contains(output, "MONITOR READOUT") || !strings.Contains(output, "30 SEC LOCAL TOKEN BARS") { t.Errorf("monitor components missing for theme %d", theme) } - } else if style == styleBenchmark { + } else if view == viewBenchmark { if !strings.Contains(output, "ALGORITHM TRIAL") || !strings.Contains(output, "RESULT MATRIX") { t.Errorf("benchmark components missing for theme %d", theme) } } else if !strings.Contains(output, "5 HOURS LOOP") || !strings.Contains(output, "1 WEEK LOOP") { - t.Errorf("quota windows missing for theme %d style %d", theme, style) + t.Errorf("quota windows missing for theme %d view %d", theme, view) } if lines := strings.Count(output, "\n") + 1; lines > 52 { - t.Errorf("theme %d style %d used %d lines, want at most 52", theme, style, lines) + t.Errorf("theme %d view %d used %d lines, want at most 52", theme, view, lines) } } } @@ -51,20 +51,20 @@ func TestViewRendersEveryThemeAndStyleWithinStandardTerminal(t *testing.T) { func TestViewReflowsAcrossTerminalDimensions(t *testing.T) { sizes := []struct{ width, height int }{{40, 16}, {40, 24}, {45, 24}, {60, 24}, {80, 24}, {120, 40}, {200, 60}} for _, size := range sizes { - for style := styleBars; style < styleCount; style++ { + for view := viewBars; view < viewCount; view++ { model := Model{ snapshot: codex.DemoSnapshot(), width: size.width, height: size.height, nextRefresh: time.Now().Add(time.Minute), - meterStyle: style, + meterView: view, } output := model.View() if got := lipgloss.Width(output); got > size.width { - t.Errorf("%s at %dx%d rendered width %d", style.name(), size.width, size.height, got) + t.Errorf("%s at %dx%d rendered width %d", view.name(), size.width, size.height, got) } if got := lipgloss.Height(output); got > size.height { - t.Errorf("%s at %dx%d rendered height %d:\n%s", style.name(), size.width, size.height, got, ansi.Strip(output)) + t.Errorf("%s at %dx%d rendered height %d:\n%s", view.name(), size.width, size.height, got, ansi.Strip(output)) } } } @@ -93,22 +93,22 @@ func TestQuotaViewsAccommodateFiveHourAdditionalAndMonthlyLimits(t *testing.T) { } for _, size := range []struct{ width, height int }{{40, 24}, {80, 24}, {120, 40}} { - for _, style := range quotaMeterStyles { + for _, view := range quotaMeterViews { model := Model{ snapshot: snapshot, width: size.width, height: size.height, - nextRefresh: now.Add(time.Minute), meterStyle: style, + nextRefresh: now.Add(time.Minute), meterView: view, } output := ansi.Strip(model.View()) if got := lipgloss.Width(output); got > size.width { - t.Errorf("%s with five limits at %dx%d rendered width %d", style.name(), size.width, size.height, got) + t.Errorf("%s with five limits at %dx%d rendered width %d", view.name(), size.width, size.height, got) } if got := lipgloss.Height(output); got > size.height { - t.Errorf("%s with five limits at %dx%d rendered height %d:\n%s", style.name(), size.width, size.height, got, output) + t.Errorf("%s with five limits at %dx%d rendered height %d:\n%s", view.name(), size.width, size.height, got, output) } if size.width >= 80 { for _, title := range []string{"5 HOURS LOOP", "1 WEEK LOOP", "MONTHLY CREDIT LIMIT", "SPARK // 1 HOUR LOOP", "SPARK // 1 DAY LOOP"} { if !strings.Contains(output, title) { - t.Errorf("%s at %dx%d omitted %q:\n%s", style.name(), size.width, size.height, title, output) + t.Errorf("%s at %dx%d omitted %q:\n%s", view.name(), size.width, size.height, title, output) } } } @@ -120,7 +120,7 @@ func TestStatusAndFooterKeepOnlyEssentialMetadata(t *testing.T) { model := Model{ snapshot: codex.DemoSnapshot(), nextRefresh: time.Now().Add(time.Minute), - meterStyle: styleBars, + meterView: viewBars, } colors := paletteFor(themeHacker) account := ansi.Strip(model.renderAccount(colors)) @@ -151,7 +151,7 @@ func TestFooterShowsAvailableAccountCredits(t *testing.T) { balance := "17000" snapshot := codex.DemoSnapshot() snapshot.RateLimits.Credits = &codex.Credits{HasCredits: true, Balance: &balance} - model := Model{snapshot: snapshot, nextRefresh: time.Now().Add(time.Minute), meterStyle: styleBars} + model := Model{snapshot: snapshot, nextRefresh: time.Now().Add(time.Minute), meterView: viewBars} footer := ansi.Strip(model.renderFooter(100, paletteFor(themeHacker))) if !strings.Contains(footer, "CREDITS 17000") { t.Fatalf("account credit balance missing from footer: %q", footer) @@ -161,54 +161,54 @@ func TestFooterShowsAvailableAccountCredits(t *testing.T) { func TestPricingFooterCentersProvenanceOnEveryPricedView(t *testing.T) { colors := paletteFor(themeHacker) model := Model{nextRefresh: time.Now().Add(time.Minute)} - pricedViews := append([]meterStyleID{styleBenchmark}, quotaStyleOrder[:]...) - for _, style := range pricedViews { - model.meterStyle = style + pricedViews := append([]meterViewID{viewBenchmark}, quotaViewOrder[:]...) + for _, view := range pricedViews { + model.meterView = view raw := model.renderFooter(100, colors) if !strings.Contains(raw, codex.StandardAPIPricingSourceURL) { - t.Errorf("%s footer does not contain pricing hyperlink: %q", style.name(), raw) + t.Errorf("%s footer does not contain pricing hyperlink: %q", view.name(), raw) continue } firstLine := strings.Split(ansi.Strip(raw), "\n")[0] label := "PRICES RETRIEVED " + codex.StandardAPIPricingRetrievedOn + " // OPENAI.COM" start := strings.Index(firstLine, label) if start < 0 { - t.Errorf("%s footer does not contain pricing provenance: %q", style.name(), firstLine) + t.Errorf("%s footer does not contain pricing provenance: %q", view.name(), firstLine) continue } center := start + len(label)/2 if center < 49 || center > 51 { - t.Errorf("%s pricing provenance center = %d, want terminal center 50: %q", style.name(), center, firstLine) + t.Errorf("%s pricing provenance center = %d, want terminal center 50: %q", view.name(), center, firstLine) } } - for _, style := range []meterStyleID{styleMonitor} { - model.meterStyle = style + for _, view := range []meterViewID{viewMonitor} { + model.meterView = view footer := model.renderFooter(100, colors) if strings.Contains(footer, codex.StandardAPIPricingSourceURL) || strings.Contains(ansi.Strip(footer), codex.StandardAPIPricingRetrievedOn) { - t.Fatalf("pricing provenance leaked into %s footer: %q", style.name(), footer) + t.Fatalf("pricing provenance leaked into %s footer: %q", view.name(), footer) } } } func TestPricingFooterRemainsResponsiveAcrossPricedViews(t *testing.T) { model := Model{nextRefresh: time.Now().Add(time.Minute)} - pricedViews := append([]meterStyleID{styleBenchmark}, quotaStyleOrder[:]...) - for _, style := range pricedViews { - model.meterStyle = style + pricedViews := append([]meterViewID{viewBenchmark}, quotaViewOrder[:]...) + for _, view := range pricedViews { + model.meterView = view for _, width := range []int{12, 24, 40, 60, 79, 80, 100} { footer := model.renderFooter(width, paletteFor(themeHacker)) for line, value := range strings.Split(footer, "\n") { if got := lipgloss.Width(value); got > width { - t.Errorf("%s width %d line %d rendered at %d: %q", style.name(), width, line, got, ansi.Strip(value)) + t.Errorf("%s width %d line %d rendered at %d: %q", view.name(), width, line, got, ansi.Strip(value)) } } hasPricing := strings.Contains(footer, codex.StandardAPIPricingSourceURL) if width < 80 && hasPricing { - t.Errorf("%s width %d unexpectedly showed pricing provenance", style.name(), width) + t.Errorf("%s width %d unexpectedly showed pricing provenance", view.name(), width) } if width >= 80 && !hasPricing { - t.Errorf("%s width %d omitted responsive pricing provenance", style.name(), width) + t.Errorf("%s width %d omitted responsive pricing provenance", view.name(), width) } } } @@ -247,7 +247,7 @@ func TestPieViewPlacesQuotaWindowsSideBySide(t *testing.T) { width: 80, height: 24, nextRefresh: time.Now().Add(time.Minute), - meterStyle: stylePie, + meterView: viewPie, } output := ansi.Strip(model.View()) foundSharedRow := false @@ -262,16 +262,16 @@ func TestPieViewPlacesQuotaWindowsSideBySide(t *testing.T) { } } -func TestGaugeGridStyleClassification(t *testing.T) { - for _, style := range []meterStyleID{styleBars, stylePie, styleConsumptionPace, styleFuel} { - if got := usesMeterGrid(style); !got { - t.Errorf("usesMeterGrid(%s) = false, want true", style.name()) +func TestGaugeGridViewClassification(t *testing.T) { + for _, view := range []meterViewID{viewBars, viewPie, viewConsumptionPace, viewFuel} { + if got := usesMeterGrid(view); !got { + t.Errorf("usesMeterGrid(%s) = false, want true", view.name()) } } - if usesMeterGrid(styleMonitor) { + if usesMeterGrid(viewMonitor) { t.Fatal("monitor should use its own full-width layout") } - if usesMeterGrid(styleBenchmark) { + if usesMeterGrid(viewBenchmark) { t.Fatal("benchmark should use its own full-width layout") } } @@ -279,8 +279,8 @@ func TestGaugeGridStyleClassification(t *testing.T) { func TestPieGridIncludesAdditionalGaugesResponsively(t *testing.T) { meters := codex.DemoSnapshot().Meters() meters = append(meters, codex.Meter{Bucket: "extra", Name: "1 DAY", Window: codex.Window{UsedPercent: 12}}) - output := ansi.Strip(renderMeterGrid(80, 20, meters, stylePie, paletteFor(themeBlueSteel))) - if columns := meterGridColumns(80, 20, len(meters), stylePie); columns < 2 { + output := ansi.Strip(renderMeterGrid(80, 20, meters, viewPie, paletteFor(themeBlueSteel))) + if columns := meterGridColumns(80, 20, len(meters), viewPie); columns < 2 { t.Fatalf("three radial gauges used %d columns, want at least 2", columns) } for _, want := range []string{"5 HOURS LOOP", "1 WEEK LOOP", "EXTRA // 1 DAY"} { @@ -300,35 +300,35 @@ func TestGridRespondsToFourRateLimitsAndTerminalShape(t *testing.T) { codex.Meter{Bucket: "extra", Name: "1 MONTH", Window: codex.Window{UsedPercent: 48}}, ) colors := paletteFor(themeUltraviolet) - for _, style := range []meterStyleID{stylePie} { - narrowColumns := meterGridColumns(100, 24, len(meters), style) - wideColumns := meterGridColumns(300, 24, len(meters), style) + for _, view := range []meterViewID{viewPie} { + narrowColumns := meterGridColumns(100, 24, len(meters), view) + wideColumns := meterGridColumns(300, 24, len(meters), view) if narrowColumns < 2 { - t.Errorf("%s used %d narrow columns, want at least 2", style.name(), narrowColumns) + t.Errorf("%s used %d narrow columns, want at least 2", view.name(), narrowColumns) } if wideColumns < narrowColumns { - t.Errorf("%s shrank from %d to %d columns in a wider terminal", style.name(), narrowColumns, wideColumns) + t.Errorf("%s shrank from %d to %d columns in a wider terminal", view.name(), narrowColumns, wideColumns) } - output := ansi.Strip(renderMeterGrid(100, 24, meters, style, colors)) + output := ansi.Strip(renderMeterGrid(100, 24, meters, view, colors)) if got := strings.Count(output, "USED"); got != 4 { - t.Errorf("%s rendered %d of 4 rate limits:\n%s", style.name(), got, output) + t.Errorf("%s rendered %d of 4 rate limits:\n%s", view.name(), got, output) } if got := lipgloss.Height(output); got != 24 { - t.Errorf("%s four-limit grid height = %d, want 24", style.name(), got) + t.Errorf("%s four-limit grid height = %d, want 24", view.name(), got) } } } func TestHorizontalStylesAlwaysFlowOneMeterPerRow(t *testing.T) { meters := codex.DemoSnapshot().Meters() - for _, style := range []meterStyleID{styleBars, styleConsumptionPace, styleFuel} { - if columns := meterGridColumns(160, 30, len(meters), style); columns != 1 { - t.Fatalf("%s used %d columns, want one", style.name(), columns) + for _, view := range []meterViewID{viewBars, viewConsumptionPace, viewFuel} { + if columns := meterGridColumns(160, 30, len(meters), view); columns != 1 { + t.Fatalf("%s used %d columns, want one", view.name(), columns) } - output := ansi.Strip(renderMeterGrid(160, 30, meters, style, paletteFor(themeHacker))) + output := ansi.Strip(renderMeterGrid(160, 30, meters, view, paletteFor(themeHacker))) for _, line := range strings.Split(output, "\n") { if strings.Contains(line, "5 HOURS LOOP") && strings.Contains(line, "1 WEEK LOOP") { - t.Fatalf("%s meters appeared side by side:\n%s", style.name(), output) + t.Fatalf("%s meters appeared side by side:\n%s", view.name(), output) } } } @@ -336,7 +336,7 @@ func TestHorizontalStylesAlwaysFlowOneMeterPerRow(t *testing.T) { func TestMeterGridKeepsRowHeightsEqualAndPadsAboveFooter(t *testing.T) { meters := codex.DemoSnapshot().Meters() - output := ansi.Strip(renderMeterGrid(80, 24, meters, styleBars, paletteFor(themeHacker))) + output := ansi.Strip(renderMeterGrid(80, 24, meters, viewBars, paletteFor(themeHacker))) lines := strings.Split(output, "\n") var tops, bottoms []int for index, line := range lines { @@ -365,23 +365,23 @@ func TestMeterGridKeepsRowHeightsEqualAndPadsAboveFooter(t *testing.T) { func TestMeterGridUsesAllocatedHeightWithoutInternalOverflow(t *testing.T) { meters := codex.DemoSnapshot().Meters() - for _, style := range []meterStyleID{stylePie, styleConsumptionPace} { - output := ansi.Strip(renderMeterGrid(116, 24, meters, style, paletteFor(themeHacker))) + for _, view := range []meterViewID{viewPie, viewConsumptionPace} { + output := ansi.Strip(renderMeterGrid(116, 24, meters, view, paletteFor(themeHacker))) height := strings.Count(output, "\n") + 1 if height != 24 { - t.Fatalf("%s grid is %d rows, want allocated height 24:\n%s", style.name(), height, output) + t.Fatalf("%s grid is %d rows, want allocated height 24:\n%s", view.name(), height, output) } } } func TestRadialViewsPlaceQuotaWindowsSideBySide(t *testing.T) { - for _, style := range []meterStyleID{stylePie} { + for _, view := range []meterViewID{viewPie} { model := Model{ snapshot: codex.DemoSnapshot(), width: 80, height: 24, nextRefresh: time.Now().Add(time.Minute), - meterStyle: style, + meterView: view, } output := ansi.Strip(model.View()) foundSharedRow := false @@ -392,7 +392,7 @@ func TestRadialViewsPlaceQuotaWindowsSideBySide(t *testing.T) { } } if !foundSharedRow { - t.Errorf("%s gauges were not side by side:\n%s", style.name(), output) + t.Errorf("%s gauges were not side by side:\n%s", view.name(), output) } } } @@ -428,7 +428,7 @@ func TestRenderMeterHandlesAdditionalBucketAndMissingReset(t *testing.T) { Name: "30 MINUTES", Window: codex.Window{UsedPercent: 75}, } - output := ansi.Strip(renderMeter(70, meter, styleFuel, colors)) + output := ansi.Strip(renderMeter(70, meter, viewFuel, colors)) for _, want := range []string{"CODEX OTHER // 30 MINUTES LOOP", "USED 75%", "RESET DATA UNAVAILABLE", "RANGE 25%"} { if !strings.Contains(output, want) { t.Errorf("rendered meter missing %q: %q", want, output) @@ -486,8 +486,8 @@ func TestTimeFormatting(t *testing.T) { func TestVisualizationClampsAndFallbacks(t *testing.T) { colors := paletteFor(themeHacker) - if output := ansi.Strip(renderVisualization(20, 0, meterStyleID(999), colors.primary, colors)); !strings.Contains(output, "░") { - t.Fatalf("unknown style did not fall back to bars: %q", output) + if output := ansi.Strip(renderVisualization(20, 0, meterViewID(999), colors.primary, colors)); !strings.Contains(output, "░") { + t.Fatalf("unknown view did not fall back to bars: %q", output) } if output := ansi.Strip(renderPie(20, 100, colors.primary, colors)); !strings.Contains(output, "100%") { t.Fatalf("full pie missing percentage: %q", output) diff --git a/intro-post.md b/intro-post.md index fe3e1d17..6946b2c1 100644 --- a/intro-post.md +++ b/intro-post.md @@ -10,7 +10,7 @@ The interface has three responsive tabs: -- **Quota** — switch between Bars, Pie, Consumption Pace, and Fuel Tank presentations. A pace-aware health signal distinguishes quota that is safely tracking the reset cycle from quota burning too quickly. Codexometer can also learn an observed standard API-equivalent estimate for primary Codex windows, showing both current consumption and an inferred 100% value with conservative confidence and visible pricing provenance. +- **Quota** — switch between Bars, Consumption Pace, Pie, and Fuel Tank presentations. A pace-aware health signal distinguishes quota that is safely tracking the reset cycle from quota burning too quickly. Codexometer can also learn an observed standard API-equivalent estimate for primary Codex windows, showing both current consumption and an inferred 100% value with conservative confidence and visible pricing provenance. - **Monitor** — record locally observed token activity by root Codex session, with scrolling graphs and compact call, activity, output, and time-to-first-token telemetry. It estimates each session's local share of observed account quota movement and highlights sessions needing input or approval when Codex exposes that state. Explicitly linked spawned agents are folded into their parent session. - **Benchmark** — run deterministic, programmatically checked coding challenges across the available model and reasoning-level combinations. Compare pass/fail results, wall time, tokens, estimated API-equivalent cost, and rankings weighted towards cost, speed, or a balance of both.