Skip to content

refactor: share format and Nerd Font handling across status widgets - #646

Merged
sirmalloc merged 3 commits into
sirmalloc:mainfrom
eric-engberg:refactor/status-widget-duplication
Oct 6, 2026
Merged

sirmalloc merged 3 commits into
sirmalloc:mainfrom
eric-engberg:refactor/status-widget-duplication

Conversation

@eric-engberg

Copy link
Copy Markdown
Contributor

Demo

After the refactor: in the line editor, n turns on the Nerd Font icon and f cycles every format on Voice, Sandbox, Remote Control, Vim Mode and Compaction Counter, which now share one implementation of both keys. Every case also renders byte-for-byte the same as before; see Testing.

Powerline

Status widgets toggling Nerd Font and cycling formats in Powerline mode

Plain

Status widgets toggling Nerd Font and cycling formats in plain mode

Summary

Voice, Sandbox, Remote Control, Vim Mode and Compaction Counter each carried their own copy of the same code:

  • reading the format from metadata, falling back to the default;
  • cycling the format with f and toggling the Nerd Font icon with n;
  • building the "(format, nerd font)" editor modifier;
  • listing the two keybinds.

A fix to one had to be made five times.

widgets/shared/format-options.ts now holds this once, on top of the existing Nerd Font helpers in shared/metadata.ts. Each widget passes its formats, its default and its rule for when a Nerd Font icon applies, and keeps its own rendering. Compaction Counter keeps its own editor modifier, which adds its trigger-split and reclaimed flags, and its other keys.

6 source files, 139 lines added and 197 removed, plus a test file. No visual change.

Testing

  • bun run lint and bun test (2,363 pass). The existing widget tests pass unchanged. New: widgets/shared/__tests__/format-options.test.ts covers the format fallback, the cycle wrapping around, the Nerd Font toggle and modifier, and when n is offered.
  • Before/after render check: all five widgets rendered on main and on this branch, in every state their own keys reach (4 to 10 per widget, 80 for Compaction Counter), raw and labeled, at all three color levels, in the TUI preview and with live data, run twice: once with voice, sandbox and remote control off (Vim in VISUAL) and once with all three on (Vim in INSERT). All 877 cases are byte-identical in both runs, as are each state's editor label and keys.
  • Built dist/ on both branches and piped a status line with all five widgets through it, on and off, in plain and Powerline mode, under Bun and Node 16, 18, 20, 22, 24 and 26: every runtime and both branches produce identical output.
  • Under Node with Vitest, the full suite fails in the same 17 files as main (all from spying on Node built-ins), and the new test passes.

eric-engberg and others added 3 commits October 4, 2026 13:45
Voice, Sandbox, Remote Control, Vim Mode and Compaction Counter each carried
their own copy of the same code: reading the format from metadata, cycling it
with (f), toggling the Nerd Font icon with (n), building the "(format, nerd
font)" modifier and listing the keybinds. Move it into
widgets/shared/format-options.ts so a fix to one applies to all five.

Behavior is unchanged: each widget passes its formats, default and Nerd Font
rule, and keeps its own rendering.
@sirmalloc
sirmalloc merged commit fb9b530 into sirmalloc:main Oct 6, 2026
3 checks passed
@eric-engberg
eric-engberg deleted the refactor/status-widget-duplication branch October 9, 2026 21:48
pcvelz added a commit to pcvelz/ccstatusline-usage that referenced this pull request Oct 11, 2026
Upstream: label prefixes editable with e (sirmalloc#601, sirmalloc#666), Session Cost Rate (sirmalloc#671) and Extra Usage Daily Budget (sirmalloc#672) widgets, own-lock-only usage lock clearing (sirmalloc#624), NO_PROXY and request deadlines, terminal control-sequence sanitizing, git hardening and linear-time parsing, shared searchable option editor (sirmalloc#649) and widget base classes (sirmalloc#646-sirmalloc#654), node: imports (sirmalloc#657), Number.* globals lint (sirmalloc#645), test waits on redraw instead of fixed delays (sirmalloc#652).

Hand edits outside conflicts:
- src/widgets/shared/searchable-option-editor.tsx: compat fix - ports the fork's ref-based input handling (Enter picks from what was just typed) into upstream's new shared editor
- src/utils/usage-fetch.ts: compat fix - fork's fetchFreshUsageData uses upstream's clearOwnUsageLock (sirmalloc#624) instead of the removed clearUsageLock
- src/widgets/ApiUsage.tsx, src/widgets/Battery.ts: compat fix - Number.isNaN/Number.parseInt for upstream's no-restricted-globals rule
- src/utils/__tests__/usage-prefetch.test.ts: compat fix - mock renamed to upstream's mockFetchUsage
- src/tui/components/__tests__/PowerlineSetup.test.ts, src/tui/components/__tests__/StatusLinePreview.test.ts, src/tui/components/__tests__/TerminalWidthMenu.test.ts: compat fix - drop the fork's flushInk import, unused after upstream's waitFor switch
- README.md: upstream notes linked docs/USAGE.md (deleted in the fork); inlined the proxy and workspace-trust text instead; upstream's own release-note entries not taken
- .fork-keep-deleted: src/widgets/FableWeeklyUsage.ts (upstream widget, unregistered in the fork, which ships WeeklyFableUsage.ts)
- src/widgets/WeeklyFableUsage.ts: compat fix - adopts upstream's shared getUsagePercentWidgetEditorDisplay, which carries the time-cursor modifier
- src/tui/__tests__/App.test.ts: fork deviation - one extra down-arrow for the fork's Off Hours main-menu row
- src/widgets/__tests__/CacheTimer.test.ts, src/widgets/CacheTimer.ts: compat fix - emoji toggle moved from e to o because upstream reserves e for edit-label
- src/widgets/AgentAddress.ts: split the session-title guard into its own if (same behaviour) so the .fork-invariants nameSource guard matches again
- docs/test-retirements.md: ledger for tests upstream renamed or replaced
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants