Skip to content

refactor(widgets): collapse the duplicated Nerd Font toggle helpers - #544

Merged
sirmalloc merged 1 commit into
sirmalloc:mainfrom
zachthedev:refactor-nerd-font-helpers
Aug 13, 2026
Merged

refactor(widgets): collapse the duplicated Nerd Font toggle helpers#544
sirmalloc merged 1 commit into
sirmalloc:mainfrom
zachthedev:refactor-nerd-font-helpers

Conversation

@zachthedev

Copy link
Copy Markdown
Contributor

Five widgets each carried their own copy of the same four Nerd Font toggle
helpers: VimMode.ts, SandboxStatus.ts, RemoteControlStatus.ts,
VoiceStatus.ts and CompactionCounter.ts. The first four are byte-identical
once the format type name is normalized; CompactionCounter's differ only by
inlining its predicate. Net -163 lines.

Pure dedup, no behavior change.

shared/metadata.ts gains isNerdFontEnabled, setNerdFontFormat and
toggleNerdFont, each taking a NerdFontFormats config as a trailing argument.
That module already owned removeMetadataKeys, which removeNerdFont reduces to
a one-liner over, and CompactionCounter was already importing from it for its
hide flag while hand-rolling these lower in the same file.

Config-object-per-call rather than a factory, since it matches how
symbol-override.tsx threads SymbolSlot and nothing in shared/ uses a
factory. It also keeps canUseNerdFont lazy, which matters because two of the
predicates read item.rawValue.

Each widget keeps only its own canUseNerdFont, which is the genuinely
per-widget half:

Widget Draws a glyph when
VimMode format is icon-dash-letter, icon-letter or icon
SandboxStatus format is glyph
RemoteControlStatus / VoiceStatus format is icon, or icon-text outside raw value mode
CompactionCounter format is the default

CompactionCounter had no such function; it inlined that predicate in three
places, including its keybind gate. It gets one as a named function, which
collapses all three.

Two things worth flagging:

  • toggleMetadataFlag looks like it should serve toggleNerdFont and does not.
    It writes nerdFont: 'false', while all five widgets delete the key and
    collapse empty metadata to undefined. Reusing it would write junk into every
    user's settings.json. removeMetadataKeys is the exact match and is what this
    uses.
  • SandboxStatus and VoiceStatus also carried a byte-identical config cwd
    resolver. Both now call resolveClaudeConfigCwd, which lives in
    claude-settings.ts next to the settings layering it feeds.

No test file is touched, which is the point: the existing suites pin the behavior
and still pass unchanged.

Tested: bun run lint clean; bun test 1866 pass, plus the
global-command-resolution failure main already has on this host and one hit
of the flaky fetchUsageData case.

VimMode, SandboxStatus, RemoteControlStatus, VoiceStatus and
CompactionCounter each carried their own copy of the same four helpers.
The first four were byte-identical apart from the format type name;
CompactionCounter's differed only by inlining its predicate. Net -163
lines.

shared/metadata.ts gains isNerdFontEnabled, setNerdFontFormat and
toggleNerdFont, each taking a NerdFontFormats config as a trailing
argument, which matches how symbol-override.tsx threads SymbolSlot. Each
widget keeps only its own canUseNerdFont predicate, the part that is
genuinely per-widget. CompactionCounter gains one as a named function,
which also covers the copy inlined in its keybind gate.

toggleMetadataFlag is deliberately not reused here: it writes
nerdFont:'false', while every one of these widgets deletes the key and
collapses empty metadata to undefined.

SandboxStatus and VoiceStatus also shared a byte-identical config cwd
resolver; both now call resolveClaudeConfigCwd next to the settings
layering it feeds.
@sirmalloc
sirmalloc merged commit 2522c11 into sirmalloc:main Aug 13, 2026
3 checks passed
@zachthedev
zachthedev deleted the refactor-nerd-font-helpers branch August 14, 2026 23:07
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