Skip to content

fix(tui): truncate labels by display width#32470

Open
CoderLuii wants to merge 1 commit into
anomalyco:devfrom
CoderLuii:fix/tui-display-width-truncation
Open

fix(tui): truncate labels by display width#32470
CoderLuii wants to merge 1 commit into
anomalyco:devfrom
CoderLuii:fix/tui-display-width-truncation

Conversation

@CoderLuii

@CoderLuii CoderLuii commented Jun 15, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #23376

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Updates the shared TUI locale truncation helpers to measure rendered width with Bun.stringWidth on 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.length counts 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-dev refresh of my earlier closed PR, #23377. The active implementation now lives in packages/tui/src/util/locale.ts, and this version covers truncate, truncateLeft, and truncateMiddle. 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/util alongside 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.ts
  • npx --yes bun@1.3.14 --cwd packages/tui typecheck
  • npx --yes bun@1.3.14 run lint completed with existing warnings outside this diff
  • npx --yes bun@1.3.14 run typecheck

Note: npx --yes bun@1.3.14 install did not complete on this Windows host because tree-sitter-powershell needs 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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Jun 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@github-actions

Copy link
Copy Markdown
Contributor

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.

@CoderLuii

CoderLuii commented Jun 15, 2026

Copy link
Copy Markdown
Author

The duplicate check is right that #31880 covers the same underlying bug, but this PR is the current-dev continuation of my original issue (#23376) and my earlier PR (#23377).

#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 packages/tui/test/util with the other TUI package tests.

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.

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.

bug(tui): agent label rendering corrupts when name contains invisible Unicode codepoints

1 participant