Skip to content

feat(widgets): show a percent widget's level as a glyph - #43

Draft
eric-engberg wants to merge 63 commits into
feat/bar-widthfrom
feat/level-glyphs
Draft

eric-engberg wants to merge 63 commits into
feat/bar-widthfrom
feat/level-glyphs

Conversation

@eric-engberg

@eric-engberg eric-engberg commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #14 (feat/bar-width) and merges #42 (glyph picker): review the two non-merge commits after the merges. It needs #14's (p) styles and #42's picker, so it goes upstream after both.

What

The percent widgets get one more style for p: a single glyph for how high the used percent runs, instead of the number:

Used Glyph (default)
under 20% 🟢
20% to 69% ⚡
70% to 89% 🔥
90% and up 🚨

To show the number as well, add a second copy of the widget and merge them, e.g. ⚡ 42.0%.

This covers Context %, Context % (usable), Block Usage, the Weekly Usage widgets, Spend Limit Usage and Extra Usage Utilization. The timers share the display code but don't get it yet.

Why

The status line in AKCodez's Claude Code status line guide puts a glyph in front of its context bar that changes with usage (🟢 → ⚡ → 🔥 → 🚨). It reads faster than a number at a glance. Making it a display style of the widget that already measures the value means one widget shows one thing: a glyph, a percentage or a bar. You combine them with a merge, which already exists, and no widget needs a leading-glyph option.

How

  • p cycles: Context % goes percentage → slider → glyph; the usage widgets percentage → block bar → slider → glyph.
  • Used, always. The glyph measures the used percent even on a widget set to show what's left, since flipping it would flip the levels. In glyph mode, u isn't offered and the label reads "Used".
  • g opens the shared glyph editor with one row per level, each labeled with its range ("Medium (20-69%)"). You can type a glyph or pick one with feat(widgets): pick a glyph from a list in the glyph editor #42's picker.
  • l edits the three break points: ←→ step to the next multiple of 5, or type a number. A break point held one above its neighbor, or typed off the fives, steps back onto them. They have to stay in order between 1 and 100, and the editor says what's wrong otherwise. Its sample shows each glyph with its range.
  • Settings store only what differs from the defaults: display: "glyph", levelGlyphLow|Medium|High|Critical and levelFromMedium|High|Critical. Break points out of range or out of order fall back to the defaults together, so the levels never overlap.
  • With feat(usage): color Extra Usage Used, Today and Utilization by break points or a gradient #41 (value colors): a glyph has no number to color, so in glyph mode Extra Usage Utilization doesn't offer v and skips value colors. The two PRs only meet in next, where the merge does this. Whichever of feat(usage): color Extra Usage Used, Today and Utilization by break points or a gradient #41 and feat(widgets): show a percent widget's level as a glyph #43 goes upstream second carries it, with a test.
  • A stored glyph mode on a widget that has none (a percent widget changed to Block Timer in the picker keeps its metadata) reads as the time: the editor no longer says "(level glyph)" for text the widget renders as time, and the first p moves on to the bar.
  • level-glyph.ts holds the levels and settings, and level-glyph-editor.tsx the break point editor and the routing of g and l. Extra Usage Utilization's render moves its "bar or percent" step into one function, now also handling the glyph.

Demo

On Context %: two Context % widgets, the first raw and merged into the second. p twice turns the first into the level glyph, l moves the High break point to 80%, and g picks 💀 as the Critical glyph from the picker, which opens on 🚨 in Travel & Places; Shift+Tab goes back to Smileys & Emotion and PgDn pages to 💀. The preview samples 90% used.

Powerline

Level glyph on Context % in Powerline mode

Plain

Level glyph on Context % in plain mode

Piped at 10%, 42%, 75% and 95% context used. Each line has a glyph merged into a percentage, then a glyph on its own.

Powerline

The level glyph at each level in Powerline mode

Plain

The level glyph at each level in plain mode

Testing

  • New tests:
    • level-glyph.test.ts (16): every level's edges, the widget's own glyphs and break points, the fallback for bad break points, the slot labels, stepping (including back onto the fives from an odd value) and typed break points with their errors, and the keys.
    • level-glyph-editor.test.ts (7 Ink tests): the break points and sample; ← and → stepping; a typed value; a rejected one and ESC; cancelling; and g editing the glyph per level.
    • Context % (5), the shared usage widget suite (2 per widget: the cycle, and the glyph and keys) and Extra Usage Utilization (3) cover the glyph by used percent, including while set to show what's left, plus the keys and the editors.
    • One existing usage suite test now starts from the glyph mode, which p reaches after the slider.
  • These were written before the code, and I watched them fail. Mutations caught: the glyph following the shown percent (usage and Utilization), the usage widgets skipping the glyph, an exclusive break point, the order check dropped, Context %'s missing keys, and the editor stepping one way. That last one was missed at first, so I added the ← test. 7 of 7.
  • A 15-run loop of the editor Ink tests had no failures.
  • The stepping fix's test was written first and failed (26 where 25 was expected, after holding High one above Medium), and a 10-run loop of the editor Ink tests after it had no failures.
  • bun test: 2826 pass, 0 fail (Bun 1.4.2). bun run lint is clean.
  • Under Node 26 vitest, the four test files touched here and the eight usage widget test files that share its suite helper pass (12 files, 226 tests).
  • runtime-check.sh -c level-glyphs-levels on the built CLI: Bun 1.4.2 and Node 26.10.0 agree byte-for-byte in plain and Powerline modes, and the TUI opens and exits under both.
  • In a real tmux pane: p twice on Context % shows (level glyph) with keys (p) bar style, (g)lyphs, (l)evels. l shows the levels. Raising High to 75% relabels the g editor's rows to Medium (20-74%) and High (75-89%).

Setting a widget's glyph meant typing it, which needs a way to type
emoji or Nerd Font icons. In the glyph editor, → now opens a picker:

- 17 groups of glyphs, paged with Tab/Shift+Tab or PgDn/PgUp: folders
  and files, dev tools, git and status, weather and time, nature,
  objects, faces and hearts, arrows, shapes, text symbols, then Nerd
  Font groups (folders, git, languages, OS and apps, status, weather)
  and Powerline glyphs.
- The arrow keys move through a group's grid, the highlighted glyph's
  name shows below it, Enter picks it and ESC goes back.

Each group's glyphs all draw at one width so the grid lines up: emoji
that terminals show two cells wide by default, and one-cell symbols and
Nerd Font icons. Names come from Unicode and the Nerd Fonts glyph names.
Typing a glyph still works.
The percent widgets (Context %, Context % (usable), Session and Weekly
Usage, Extra Usage Utilization) get one more style for (p): a single
glyph for how high the used percent runs, 🟢 under 20%, ⚡ from 20%, 🔥
from 70% and 🚨 from 90%. It replaces the number; a second copy of the
widget merged beside it shows both, e.g. `⚡ 42.0%`.

The glyph always measures what's used, so (u) isn't offered in this
mode. (g) sets the glyph for each level in the glyph editor, picker
included, and (l) the three break points. Settings store only what
differs from the defaults: `levelGlyph<Level>` and `levelFrom<Level>`.
A row's glyphs are unique within its group, so they make a stable key
where the row's position doesn't.
The curated groups hold about 280 of Nerd Fonts' 10,600 icons, so many,
like the pull request created, merged, closed and draft icons, weren't
there. Typing in the picker now searches every glyph by name: the
curated groups' and all of Nerd Fonts', matching every word of the
search (`pull req draft`). The groups stay for browsing; a long list of
matches scrolls.

The full set comes from Nerd Fonts' glyph names
(`scripts/generate-nerd-font-glyphs.ts` regenerates it), with aliases
sharing a codepoint merged into one entry. The picker loads all its glyph
data when it opens, from its own build chunk, so the status line's
render path no longer loads even the curated groups.
The full Nerd Font set was only reachable by searching. After the 17
curated groups, the picker now has a group for each icon set: Codicons,
Devicons, Font Awesome, Material Design (6,896 icons), Octicons, Weather
Icons and the rest, 33 groups in all. PgUp/PgDn move a page within a
group and Tab/Shift+Tab switch groups (PgUp/PgDn switched groups
before).
A break point held one above its neighbor, or typed, kept its odd offset
on every later step (21, 26, 31...), so it never landed on a multiple of
5 again. Steps now go to the next multiple of 5 in that direction.
The arrow and paging keys now work out where the highlight goes in one
function, so the key handler only decides between picking, going back,
moving and typing. The Nerd Font name format builds its alias list
first, and the generator script reads glyphnames.json from the current
directory instead of taking a path.
The picker's search found every Nerd Font icon but only the curated
emoji and symbols, so most emoji (🤡 clown, 🤢 nauseated) couldn't be
found at all. It now also searches every fully-qualified Unicode 18.0
emoji, without the skin tone variants, and every character in the
Unicode symbol blocks (arrows, box drawing, math, dingbats and more),
plus a few common ones from elsewhere (§ ± × ÷ π ...).

scripts/generate-unicode-glyphs.ts generates the data from Unicode's
emoji-test.txt and UnicodeData.txt, as the Nerd Font data is generated
from glyphnames.json. It loads with the rest of the picker's data, so
the status line still never loads it. A glyph is listed once, under its
first name, and found by any of its names; an emoji's text and emoji
forms (❤ and ❤️) stay separate glyphs.
Ctrl+T in the glyph picker cycles the emoji skin tone: the default, then
light, medium-light, medium, medium-dark and dark. Every emoji that takes
a tone (332 of them) shows and picks in it, in the groups and in search,
with both people toned in a two-person emoji. The tone is a new optional
setting, emojiSkinTone, so it's remembered next time; an unknown value
falls back to the default rather than invalidating the settings.

The Unicode generator records each such emoji's light tone version,
worked out from Unicode's own toned versions (the emoji selector goes
when a tone comes in, and both people take it), keeping only emoji that
have all five tones. The picker turns that into the chosen tone. It
reads and saves the tone through a small context that the line editor
provides, so the widget editors in between don't change.

The glyph editor now shows a multi-part emoji whole (👍🏾, 👩‍💻). Ink lays
out each part as its own character, so the "(default: …)" text after it
overwrote the tone or the rest of the emoji; the two are one Text now.
A new object on every app render made everything reading the context
redraw with it; the value is memoized on the tone now.
# Conflicts:
#	src/widgets/shared/symbol-override.tsx
# Conflicts:
#	src/widgets/ExtraUsageUtilization.ts
#	src/widgets/shared/context-percentage-widget-base.ts
#	src/widgets/shared/symbol-override.tsx
The picker's groups are now a hand-picked list of 388 glyphs, chosen
from every Unicode emoji, the Unicode symbol blocks and the Nerd Font
icon sets. There are many more faces (115 in Smileys & Emotion), so a
widget can show a good or a bad mood, along with thumbs up and down,
pointing hands, keycaps and colored squares. Emoji follow Unicode's
categories, then come the one-cell arrows and symbols, then one Nerd
Font group that includes the Powerline glyphs. Names are Unicode's emoji
names ("thumbs up", not "thumbs up sign"). Country flags are left to
search.

A group can now be longer than one page, and the IEC power symbol sits
with the Nerd Font icons, since many terminal fonts lack it.
The 16 Nerd Font icon sets are no longer groups to page through after
the curated ones, so tiny sets like Indentation (one glyph) and Material
Design's 6,896 icons are gone from Tab. The curated Nerd Font group holds
the useful icons, and searching still finds all 10,617. PgUp/PgDn still
move a page within a group, which the bigger groups need.
…n it

The picker opened on the emoji a toned glyph is made from, but showed it
in the saved skin tone. With 👍🏾 set and the default tone saved, it
highlighted 👍, and Enter picked 👍: opening the picker and confirming
dropped the tone the glyph had.

The picker now opens in the current glyph's own tone when it has one, so
Enter keeps 👍🏾, and both people of a two-person emoji (🧑🏾‍🤝‍🧑🏾) that
search finds keep theirs. That tone stays in the picker: the saved tone
changes only on Ctrl+T, which cycles on from the tone shown. A glyph
without a tone opens in the saved tone as before.
Changing a widget's type keeps its metadata, so a percent widget in its
level glyph mode keeps display: 'glyph' when it becomes Block Timer, Block
Reset Timer or Weekly Reset Timer. The timers have no glyph and render
their time, but Block Timer and Block Reset Timer named the mode
"(level glyph)" on the editor row, and on all three the first (p) only
rewrote the mode to the time, so it seemed to do nothing.

The shared modifier text and (p) cycle now honor the glyph only for the
widgets that offer it, as the cycle already did when choosing what comes
after the slider. The others read a stored glyph as the time, as they
render it: the editor row shows the time's modifiers, and (p) goes on to
the block bar.
A folder is the natural glyph for the directory widgets (Current Working
Dir, Git Root Dir), but the Objects group had no folder emoji: the
curation left out Unicode's whole office subgroup. Search found them,
but browsing didn't.

Add 📁 file folder and 📂 open file folder to Objects, in the curated
page order (after the money glyphs, before the locks). The groups now
hold 390 glyphs.
Nerd Fonts draw their zap icon (nf-oct-zap) on U+26A1, the high voltage
emoji. In a terminal set to a Nerd Font, the font's own glyph wins, so
the picker's ⚡ showed as a flat icon rather than the color emoji.

The curated ⚡ now carries the emoji selector (U+FE0F), which asks the
terminal for the emoji. ⚡ is an emoji by default, so the selector makes
no new glyph: search keeps one entry for it, as before, found by "high
voltage", "high voltage sign" or "zap". An emoji whose plain form is
text, like ❤ and ❤️, still lists both forms.
The level glyph's medium default was a bare ⚡ (U+26A1), where Nerd
Fonts draw their zap icon. In a terminal set to a Nerd Font, the status
line showed that flat icon between the color 🟢 and 🔥.

Default to ⚡ with the emoji selector (U+FE0F), as the glyph picker now
offers it, so the terminal draws the emoji. A glyph someone set
themselves is kept as they typed it.
Custom Symbol has its own editor rather than the glyph editor, so → did
nothing there and its symbol could only be typed. → now opens the same
picker, on the current symbol: Enter picks the highlighted glyph and ESC
goes back without changing it. Typing, Backspace and Enter still work as
before.
# Conflicts:
#	src/tui/App.tsx
#	src/widgets/CustomSymbol.tsx
#	src/widgets/shared/symbol-override.tsx
…glyphs

# Conflicts:
#	docs/USAGE.md
#	src/tui/App.tsx
#	src/widgets/shared/symbol-override.tsx
…dgets

Session Usage is Block Usage on main now, and the new Spend Limit Usage
shares the usage percent widgets' styles, level glyph included.
The glyph data loads from its own build chunk the first time a picker
opens, and the chunk's file name is a content hash that changes with
almost every release. If ccstatusline's install is replaced while the
TUI is open (the TUI's own Updates action runs a global install, or an
npx status line render reinstalls a newer release into the same cache),
the running bundle still imports the old chunk name. Opening any glyph
picker then showed "Loading glyphs…" and the process exited with
"Cannot find module …/glyph-catalog-<hash>.js", losing every unsaved
edit: nothing handled the import's rejection. The rejected promise also
stayed cached, so every later picker in the session failed the same way.

The picker now says it couldn't load the glyph list and to restart
ccstatusline, and ESC goes back to the editor with its edits intact. A
failed load is no longer cached, so the next picker that opens tries
again.
# Conflicts:
#	src/widgets/ExtraUsageUtilization.ts
#	src/widgets/shared/context-percentage-widget-base.ts
#	src/widgets/shared/usage-percent-widget.ts
…xt one

The glyph picker tests wait for the picker's grid to show before pressing
the next key, but their wait returned as soon as the text appeared. Ink's
useInput attaches the grid's key handler in an effect React runs after it
draws the frame, on a later setImmediate turn. On a busy machine the poll
could see the frame first and send the key straight away; the key then
reached the loading screen's ESC-only handler and was dropped, and the test
failed with "No redraw after ...", a different test each run.

waitForOutput now waits with wait-for-ink's waitFor, which retries the check
and then gives React two setImmediate turns, as the editor harness already
does after every key.
# Conflicts:
#	docs/USAGE.md
#	src/tui/App.tsx
#	src/widgets/shared/symbol-override.tsx
# Conflicts:
#	docs/USAGE.md
#	src/tui/App.tsx
#	src/widgets/shared/symbol-override.tsx
#	src/widgets/shared/usage-display.ts
# Conflicts:
#	docs/USAGE.md
↑ and ↓ each spelled out the wrap-around in the editor's key handler,
which the picker key and the Shift+Tab toggle had already made long. One
helper keeps it short; a test now covers the wrap in both directions.
The level glyph stays the last style (p) cycles to, now after the line:
text, block, slider, line, glyph on the percent widgets, and percentage,
slider, line, glyph on Context %. The timers still go from the line back to
text.
@sonarqubecloud

sonarqubecloud Bot commented Nov 8, 2026

Copy link
Copy Markdown

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.

1 participant