diff --git a/README.md b/README.md index b4369f9b..66044697 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,8 @@ codexometer --codex /path/to/codex | `Tab` | Select the next top-level tab: Quota, Monitor, or Benchmark | | `Shift+Tab` | Select the previous top-level tab | | `r` | Refresh quota data immediately | -| `s` | Cycle presentation style in Quota; start recording in Monitor | +| `v` | Cycle the active Quota view | +| `s` | Start recording (Monitor only) | | `p` | Stop and take a final up-to-date reading (Monitor view only) | | `b` | Run the selected challenge (Benchmark view only) | | `a` | Arm, then confirm, Run All (Benchmark view only) | @@ -228,9 +229,9 @@ 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 -with `s`. Codexometer remembers the selected Quota presentation when you leave +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 Style +The footer presents the remaining actions as clickable buttons, including View only while Quota is active. Move the pointer over a tab or button to highlight it, or click it to activate it. Controls pulse briefly when activated by mouse or keyboard. The keyboard assignments remain available in terminals without @@ -299,7 +300,7 @@ The default remains the original green hacker-terminal presentation. ## Views and quota presentations The top-level tabs are **Quota**, **Monitor**, and **Benchmark**. Within Quota, -choose one of these four presentations with its sub-tab or `s`: +choose one of these four views with its sub-tab or `v`: 1. **Bars** — chunky quota bars, with one full-width rate-limit window per row. 2. **Pie** — clockwise-filled circles rendered on a 2×4 sub-cell Braille canvas @@ -793,8 +794,8 @@ selected font includes block, arrow, and emoji glyphs. ### The terminal is too small Codexometer adapts its header and meter widths, but rich gauges need enough -rows to display every quota window. Increase the pane height or press `s` in -Quota to return to the compact default bar style. +rows to display every quota window. Increase the pane height or press `v` in +Quota to return to the compact default Bars view. ### Monitor remains at zero diff --git a/internal/ui/meters.go b/internal/ui/meters.go index 3904f171..203f8fba 100644 --- a/internal/ui/meters.go +++ b/internal/ui/meters.go @@ -413,27 +413,7 @@ func renderConsumptionPaceSized(width, height, pace int, available bool, colors } else if pace < 0 { markerColor = colors.danger } - var axis strings.Builder - for column := 0; column < width; column++ { - r := '─' - switch column { - case 0: - r = '├' - case center: - r = '┼' - case width - 1: - r = '┤' - } - if column == marker { - if available { - axis.WriteString(lipgloss.NewStyle().Bold(true).Foreground(markerColor).Render("◆")) - } else { - axis.WriteString(lipgloss.NewStyle().Bold(true).Foreground(colors.warning).Render("?")) - } - continue - } - axis.WriteString(colors.dimmed().Render(string(r))) - } + axis := paceAxis(width, center, marker, pace, available, markerColor, colors) status := "PACE DATA UNAVAILABLE" if available { @@ -450,7 +430,7 @@ func renderConsumptionPaceSized(width, height, pace int, available bool, colors caption := colors.dimmed().Render(ansi.Truncate("CONSUMPTION PACE // TIME - USAGE", width, "")) labels := colors.dimmed().Render(paceScaleLabels(width)) - lines := []string{caption, labels, axis.String(), status} + lines := []string{caption, labels, axis, status} if height <= 0 { height = len(lines) } @@ -465,6 +445,55 @@ func renderConsumptionPaceSized(width, height, pace int, available bool, colors return lipgloss.Place(width, height, lipgloss.Center, lipgloss.Center, strings.Join(lines, "\n")) } +func paceAxis(width, center, marker, pace int, available bool, markerColor lipgloss.Color, colors palette) string { + if width < 3 { + value := "?" + color := colors.warning + if available { + value = "▲" + color = markerColor + } + return lipgloss.PlaceHorizontal(width, lipgloss.Center, lipgloss.NewStyle().Bold(true).Foreground(color).Render(value)) + } + + carriageStart := min(max(marker-1, 0), width-3) + carriageEnd := carriageStart + 2 + carriage := "[▲]" + if !available { + carriage = "[?]" + markerColor = colors.warning + } + carriageRunes := []rune(carriage) + carriageStyle := lipgloss.NewStyle().Bold(true).Foreground(colors.background).Background(markerColor) + trailStyle := lipgloss.NewStyle().Foreground(markerColor) + dimmed := colors.dimmed() + + var axis strings.Builder + for column := 0; column < width; column++ { + if column >= carriageStart && column <= carriageEnd { + axis.WriteString(carriageStyle.Render(string(carriageRunes[column-carriageStart]))) + continue + } + r := '─' + switch column { + case 0: + r = '├' + case center: + r = '┼' + case width - 1: + r = '┤' + } + inTrail := available && ((pace > 0 && column > center && column < carriageStart) || + (pace < 0 && column < center && column > carriageEnd)) + if inTrail { + axis.WriteString(trailStyle.Render("━")) + continue + } + axis.WriteString(dimmed.Render(string(r))) + } + return axis.String() +} + func paceScaleLabels(width int) string { if width < 11 { return ansi.Truncate(lipgloss.PlaceHorizontal(width, lipgloss.Center, "- 0 +"), width, "") diff --git a/internal/ui/meters_test.go b/internal/ui/meters_test.go index 616e7b4f..65ad8b3d 100644 --- a/internal/ui/meters_test.go +++ b/internal/ui/meters_test.go @@ -215,13 +215,34 @@ func TestConsumptionPaceGaugeUsesSignedHorizontalAxis(t *testing.T) { if !strings.Contains(negative, "DEFICIT -25 POINTS") { t.Fatalf("negative pace gauge missing deficit: %q", negative) } - positiveMarker := runeColumn(lineContainingRune(positive, '◆'), '◆') - negativeMarker := runeColumn(lineContainingRune(negative, '◆'), '◆') + if !strings.Contains(positive, "[▲]") || !strings.Contains(negative, "[▲]") { + t.Fatalf("pace gauges do not use the highlighted sliding carriage: positive=%q negative=%q", positive, negative) + } + if !strings.Contains(positive, "━") || !strings.Contains(negative, "━") { + t.Fatalf("pace gauges do not show a trail from zero: positive=%q negative=%q", positive, negative) + } + positiveMarker := runeColumn(lineContainingRune(positive, '▲'), '▲') + negativeMarker := runeColumn(lineContainingRune(negative, '▲'), '▲') if positiveMarker <= 20 || negativeMarker >= 20 { t.Fatalf("pace markers did not straddle zero: negative=%d positive=%d", negativeMarker, positiveMarker) } } +func TestConsumptionPaceCarriageStaysInsideResponsiveAxis(t *testing.T) { + colors := paletteFor(themeNightshade) + for _, width := range []int{1, 2, 3, 4, 9, 20, 41, 80} { + for _, pace := range []int{-100, -25, 0, 25, 100} { + output := renderConsumptionPaceSized(width, 1, pace, true, colors) + if got := lipgloss.Width(output); got != width { + t.Errorf("width %d pace %d rendered width %d: %q", width, pace, got, ansi.Strip(output)) + } + if got := lipgloss.Height(output); got != 1 { + t.Errorf("width %d pace %d rendered height %d", width, pace, got) + } + } + } +} + func TestRadialGraphicsUseLargeCircularCanvases(t *testing.T) { colors := paletteFor(themeUltraviolet) plain := ansi.Strip(renderPie(52, 62, colors.primary, colors)) diff --git a/internal/ui/model.go b/internal/ui/model.go index cc57f5a6..53bbaacb 100644 --- a/internal/ui/model.go +++ b/internal/ui/model.go @@ -236,7 +236,7 @@ type footerButtonID int const ( footerButtonNone footerButtonID = iota footerButtonTheme - footerButtonStyle + footerButtonView footerButtonRefresh footerButtonQuit footerButtonMonitorGo @@ -267,7 +267,7 @@ var footerButtonDefinitions = []footerButton{ var quotaFooterButtonDefinitions = []footerButton{ {id: footerButtonTheme, label: "[ (T)HEME ]", compact: "[T]"}, - {id: footerButtonStyle, label: "[ (S)TYLE ]", compact: "[S]"}, + {id: footerButtonView, label: "[ (V)IEW ]", compact: "[V]"}, {id: footerButtonRefresh, label: "[ (R)EFRESH ]", compact: "[R]"}, {id: footerButtonQuit, label: "[ (Q)UIT ]", compact: "[Q]"}, } @@ -306,12 +306,13 @@ func (m Model) Update(message tea.Msg) (tea.Model, tea.Cmd) { case "t": return m.pressFooterButton(footerButtonTheme) case "s": - if m.meterStyle.isQuota() { - return m.pressFooterButton(footerButtonStyle) - } if m.meterStyle == styleMonitor { return m.pressFooterButton(footerButtonMonitorGo) } + case "v": + if m.meterStyle.isQuota() { + return m.pressFooterButton(footerButtonView) + } case "tab": return m.pressMainTab(m.currentMainTab().next()) case "shift+tab": @@ -591,7 +592,7 @@ func (m Model) activateFooterButton(button footerButtonID) (Model, tea.Cmd) { switch button { case footerButtonTheme: m.theme = m.theme.next() - case footerButtonStyle: + case footerButtonView: if m.meterStyle.isQuota() { m.meterStyle = m.meterStyle.nextQuota() m.quotaMeterStyle = m.meterStyle diff --git a/internal/ui/model_test.go b/internal/ui/model_test.go index 9032e617..90aaa88e 100644 --- a/internal/ui/model_test.go +++ b/internal/ui/model_test.go @@ -173,10 +173,10 @@ func TestFooterButtonsSupportHoverAndMouseClicks(t *testing.T) { t.Fatalf("theme click selected theme=%d flash=%d, want theme=%d flash=%d", model.theme, model.flashedButton, themeRust, footerButtonTheme) } - updated, command = model.Update(footerMouseMessage(t, model, footerButtonStyle, tea.MouseActionPress)) + updated, command = model.Update(footerMouseMessage(t, model, footerButtonView, tea.MouseActionPress)) model = updated.(Model) - if command == nil || model.meterStyle != stylePie || model.flashedButton != footerButtonStyle { - t.Fatalf("style click selected style=%d flash=%d", model.meterStyle, model.flashedButton) + if command == nil || model.meterStyle != stylePie || model.flashedButton != footerButtonView { + t.Fatalf("view click selected view=%d flash=%d", model.meterStyle, model.flashedButton) } updated, command = model.Update(footerMouseMessage(t, model, footerButtonRefresh, tea.MouseActionPress)) @@ -192,16 +192,16 @@ func TestFooterButtonsSupportHoverAndMouseClicks(t *testing.T) { } } -func TestStyleFooterButtonOnlyExistsOnQuota(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} - if _, ok := footerButtonByID(model, footerButtonStyle); ok { - t.Fatalf("%s footer exposed the Style button", style.name()) + if _, ok := footerButtonByID(model, footerButtonView); ok { + t.Fatalf("%s footer exposed the View button", style.name()) } for y := 0; y < model.height; y++ { for x := 0; x < model.width; x++ { - if got := model.footerButtonAt(x, y); got == footerButtonStyle { - t.Fatalf("%s exposed hidden Style hit target at %d,%d", style.name(), x, y) + if got := model.footerButtonAt(x, y); got == footerButtonView { + t.Fatalf("%s exposed hidden View hit target at %d,%d", style.name(), x, y) } } } @@ -321,7 +321,7 @@ func TestFooterButtonLabelsEmbedHotkeysWithPadding(t *testing.T) { } quota, separator := footerButtonLayout(100, true) - quotaWant := []string{"[ (T)HEME ]", "[ (S)TYLE ]", "[ (R)EFRESH ]", "[ (Q)UIT ]"} + quotaWant := []string{"[ (T)HEME ]", "[ (V)IEW ]", "[ (R)EFRESH ]", "[ (Q)UIT ]"} if separator != " " || len(quota) != len(quotaWant) { t.Fatalf("unexpected Quota footer layout: separator=%q buttons=%#v", separator, quota) } @@ -330,6 +330,15 @@ func TestFooterButtonLabelsEmbedHotkeysWithPadding(t *testing.T) { t.Errorf("Quota button %d label = %q, want %q", index, quota[index].label, label) } } + compactQuota, separator := footerButtonLayout(20, true) + if separator != " " { + t.Fatalf("compact Quota separator = %q, want one space", separator) + } + for index, label := range []string{"[T]", "[V]", "[R]", "[Q]"} { + if compactQuota[index].label != label { + t.Errorf("compact Quota button %d label = %q, want %q", index, compactQuota[index].label, label) + } + } } func TestFooterLayoutNeverHitTestsControlsTruncatedByTheme(t *testing.T) { diff --git a/internal/ui/tabs_test.go b/internal/ui/tabs_test.go index a2b015d0..aa74f1ad 100644 --- a/internal/ui/tabs_test.go +++ b/internal/ui/tabs_test.go @@ -176,18 +176,24 @@ func TestQuotaStyleIsRememberedAcrossMainTabNavigation(t *testing.T) { } } -func TestSIsContextualStyleAndMonitorStartHotkey(t *testing.T) { +func TestVSelectsQuotaViewAndSOnlyStartsMonitor(t *testing.T) { model := Model{meterStyle: styleBars} for _, want := range []meterStyleID{stylePie, styleConsumptionPace, styleFuel, styleBars} { - updated, command := model.Update(key('s')) + updated, command := model.Update(key('v')) model = updated.(Model) - if command == nil || model.meterStyle != want || model.quotaMeterStyle != want || model.flashedButton != footerButtonStyle { - t.Fatalf("S selected style=%d remembered=%d flash=%d, want style=%d", model.meterStyle, model.quotaMeterStyle, model.flashedButton, want) + 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) } } + sequence := model.flashSequence + updated, command := model.Update(key('s')) + model = updated.(Model) + if command != nil || model.meterStyle != styleBars || model.flashSequence != sequence { + t.Fatal("S changed the Quota view") + } model = Model{meterStyle: styleMonitor, monitorState: monitorIdle} - updated, command := model.Update(key('s')) + 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)