Skip to content

Measure the new session label in cells, not characters - #4

Merged
TABmk merged 2 commits into
TABmk:masterfrom
sharamanie:fix/cjk-wide-label
Nov 4, 2026
Merged

TABmk merged 2 commits into
TABmk:masterfrom
sharamanie:fix/cjk-wide-label

Conversation

@sharamanie

@sharamanie sharamanie commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What this fixes

The framed New Session button pads its label to the sidebar's width using String.length, which counts a full-width character as one cell. With a CJK label the row comes up short by one cell per character, so the right border sits past the frame and the label looks squeezed next to the arrow:

final-after

After this change every row of the frame is 40 cells wide for new session, 新会话, 新しいセッション and 새 세션 alike.

What changed

  • src/pieces/new-session.js — measure the label in cells (two for an East Asian Wide or Fullwidth character, one otherwise) and pad to room cells instead of room characters. The ellipsis that trims an over-long label now cuts at a cell budget too, so it no longer splits a wide character.
  • lib/client.js — rebuilt with npm run build.

English labels are byte-for-byte unchanged: with no wide characters, cells and characters are the same number.

There is a second half to this

Padding correctly is only part of it. The glyphs were also being drawn one cell wide, because mount() in ascii.rest advances one cell per character. That is not this repository's bug, and I have opened bas3line/ascii#79 for it. With this patch alone the label is positioned correctly but the glyphs still overlap; with that one merged, the button renders properly.

If you would rather wait, this PR is still correct on its own — it fixes the frame width and the trim, both of which stay wrong regardless of how glyphs are rasterised.

Verification

  • npm run build — clean
  • Frame width measured at 40 cells for each of the labels above
  • Rendered in a live DeepSeek Harness Web client at the 252px sidebar width: three distinct glyphs, arrow aligned to the right edge

The framed button pads its label to the sidebar's width with
`String.length`, which counts a full-width character as one. A label
with CJK characters therefore came up short by one cell per character
and pushed the right border past the frame; the ellipsis cut long
labels at the wrong place for the same reason.

Measure in cells instead: two for an East Asian Wide or Fullwidth
character, one for the rest, and cut to a cell budget rather than to a
character count. English labels render exactly as before.

This is the label half of the CJK rendering problem. The glyphs
themselves were also being drawn a cell wide, which is ascii.rest's
mount(): see bas3line/ascii#79.
@sharamanie

Copy link
Copy Markdown
Contributor Author

mainly fixed by AI, and im very appreciate to your theme, it is so nice for a retro style enthusiast like me

fit() can return room-1 cells when a wide character does not fit, so
always pad after fitting. The glint, arrow shaft and border checks now
walk cell columns instead of string indices, so wide labels animate
correctly.
@TABmk
TABmk merged commit b08a885 into TABmk:master Nov 4, 2026
@TABmk

TABmk commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Thanks, merged! I also opened #5 so I don't forget to bump the ascii.rest version once your issue is fixed

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