Skip to content

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

Closed
CoderLuii wants to merge 3 commits into
anomalyco:devfrom
CoderLuii:fix/tui-display-width-truncation
Closed

CoderLuii wants to merge 3 commits 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?

Note: npx --yes [email protected] 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 [email protected] --cwd packages/tui test test/util/locale.test.ts

Tested: npx --yes [email protected] --cwd packages/tui typecheck

Tested: npx --yes [email protected] run lint

Tested: npx --yes [email protected] run typecheck

Not-tested: Clean bun install completion on this Windows host; tree-sitter-powershell native build requires Visual Studio C++ build tools

Related: #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.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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