fix(tui): truncate labels by display width#32470
Conversation
TUI truncation used UTF-16 code-unit length, so labels with zero-width prefixes could fit on screen but still lose visible characters. Use display-width truncation on grapheme boundaries for the shared locale helpers. Constraint: Current dev routes locale helpers through packages/tui/src/util/locale.ts Rejected: Strip invisible characters here | truncation should measure rendered width without changing caller text Confidence: high Scope-risk: narrow Tested: npx --yes bun@1.3.14 --cwd packages/tui test test/util/locale.test.ts Tested: npx --yes bun@1.3.14 --cwd packages/tui typecheck Tested: npx --yes bun@1.3.14 run lint Tested: npx --yes bun@1.3.14 run typecheck Not-tested: Clean bun install completion on this Windows host; tree-sitter-powershell native build requires Visual Studio C++ build tools Related: anomalyco#23376
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
The following comment was made by an LLM, it may be inaccurate: Potential duplicate found:
Check if PR #31880 is still open or if this PR #32470 supersedes it with updated implementations. |
|
The duplicate check is right that #31880 covers the same underlying bug, but this PR is the current- #31880 was opened after that issue and earlier PR. This refresh keeps my original fix current and has two implementation differences: the truncation walks grapheme segments instead of raw codepoints, and the regression test lives under So the intent here is not to dismiss the overlapping PR. It is to keep my original fix path active and land the rendered-width correction upstream instead of leaving it to downstream plugin/container patches. |
Issue for this PR
Closes #23376
Type of change
What does this PR do?
Updates the shared TUI locale truncation helpers to measure rendered width with
Bun.stringWidthon grapheme segments instead of UTF-16 string length.#23376 is the original issue I opened for this bug. It shows zero-width codepoints reaching the TUI in agent labels.
str.lengthcounts those codepoints even though they render as zero columns, so a label can fit on screen and still lose visible characters during truncation.This is the current-
devrefresh of my earlier closed PR, #23377. The active implementation now lives inpackages/tui/src/util/locale.ts, and this version coverstruncate,truncateLeft, andtruncateMiddle. Related reports: #23049 and #22131.The duplicate bot pointed to #31880, which is for the same underlying bug and was opened after #23376/#23377. This PR is not invalidating that work; it keeps my original issue and earlier PR current, and differs by walking grapheme segments instead of raw codepoints, with tests under
packages/tui/test/utilalongside the rest of the TUI package tests.Downstream, HolyClaude ships OpenCode in the full image, so fixing the TUI width math upstream is better than carrying a container or plugin-only patch.
How did you verify your code works?
npx --yes bun@1.3.14 --cwd packages/tui test test/util/locale.test.tsnpx --yes bun@1.3.14 --cwd packages/tui typechecknpx --yes bun@1.3.14 run lintcompleted with existing warnings outside this diffnpx --yes bun@1.3.14 run typecheckNote:
npx --yes bun@1.3.14 installdid not complete on this Windows host becausetree-sitter-powershellneeds Visual Studio C++ build tools. The checks above still ran with the repo's pinned Bun version.Screenshots / recordings
No screenshot. This is a terminal width-calculation fix; the visible reproduction and byte evidence are in #23376.
Checklist