Skip to content

fix(tui): measure wide characters by display cells#9

Merged
hamidi-dev merged 2 commits into
hamidi-dev:mainfrom
Gheat1:fix/width
Jul 7, 2026
Merged

fix(tui): measure wide characters by display cells#9
hamidi-dev merged 2 commits into
hamidi-dev:mainfrom
Gheat1:fix/width

Conversation

@Gheat1

@Gheat1 Gheat1 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

CJK/emoji session titles and project paths were measured in codepoints, so wide glyphs overflowed their column budget, wrapped into the next row, and broke the reverse-video selection bar.

Adds display_width / clip / pad to formatting.py (stdlib unicodedata.east_asian_width, combining marks count zero, isascii() fast path for the render loops — an approximation that leaves emoji ZWJ sequences alone, noted in a comment). shorten and short_path truncate by cells, Renderer.write clips by cells so a wide char never straddles the budget, and the user-content row builders (highlight bars, modals, toasts, the Turns subtotal alignment) pad by cells. Fixed-vocabulary/ASCII-guaranteed content (headers, money, dates, model ids) deliberately stays on len().

Second commit: money_label spelled sub-cent as <$.01 while money() uses <$0.01; aligned (the price-split paren group widens by one to stay flush right).

Tested: 6 new tests (cell counting, clipping never exceeding the budget, exact-width padding, CJK shorten/short_path); suite 310/310, ruff clean; --demo --html smoke-checked.

Gheat1 added 2 commits July 7, 2026 16:55
CJK/emoji session titles and project paths were measured in codepoints,
so wide glyphs overflowed their column budget, wrapped into the next
row, and broke the reverse-video selection bar. Add display_width /
clip / pad to formatting (east_asian_width-based, combining marks zero
-- an approximation that leaves emoji ZWJ sequences alone), make
shorten and short_path truncate by cells, clip Renderer.write by cells,
and pad user-content rows (highlight bars, modals, toasts) by cells.
The compact bar label spelled sub-cent as <$.01 while money() uses
<$0.01; align the two (the price-split cells widen by one to keep the
parens group flush right).
@hamidi-dev

Copy link
Copy Markdown
Owner

Great one — measuring by cells fixes the CJK column overflow cleanly, and I like that emoji ZWJ/flags are called out as the known approximation rather than papered over. Thanks!

@hamidi-dev hamidi-dev merged commit 3b196e3 into hamidi-dev:main Jul 7, 2026
4 checks passed
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