fix(prompts): truncate wide-character box titles by display width#578
Open
greymoth-jp wants to merge 1 commit into
Open
fix(prompts): truncate wide-character box titles by display width#578greymoth-jp wants to merge 1 commit into
greymoth-jp wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 2aee058 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Automation signals@greymoth-jp Activity patterns show signs of automation. Classification:
Analyzed 200 public events via @unveil/identity |
43081j
reviewed
Jun 30, 2026
|
|
||
| function truncateToWidth(str: string, maxWidth: number): string { | ||
| const ellipsis = '...'; | ||
| const target = maxWidth - stringWidth(ellipsis); |
Collaborator
There was a problem hiding this comment.
the ellipsis is constant so should be moved out of the function, and the length doesn't need to use stringWidth since we know it has no wide characters
43081j
reviewed
Jun 30, 2026
| return [leftPadding, rightPadding]; | ||
| } | ||
|
|
||
| function truncateToWidth(str: string, maxWidth: number): string { |
Collaborator
There was a problem hiding this comment.
this should really be in common.ts since it will be useful in other places too
43081j
reviewed
Jun 30, 2026
Comment on lines
+106
to
+110
| if (width + charWidth > target) { | ||
| break; | ||
| } | ||
| result += char; | ||
| width += charWidth; |
Collaborator
There was a problem hiding this comment.
Suggested change
| if (width + charWidth > target) { | |
| break; | |
| } | |
| result += char; | |
| width += charWidth; | |
| width += charWidth; | |
| if (width > target) { | |
| break; | |
| } | |
| result += char; |
to avoid computing it twice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
box()measures the title and every line withfast-string-width, but it truncates an over-long title withtitle.slice(0, maxTitleLength - 3), which counts UTF-16 code units rather than display columns.maxTitleLengthis a display-width budget, so for a wide-character (CJK/full-width) title the sliced result is still far too wide. The top border comes out ragged, and oncegetPaddingForLinereturns a negative remainder,'─'.repeat(...)throwsRangeError: Invalid count value.Repro on
main:The fix replaces the code-unit slice with a small
truncateToWidthhelper that accumulates characters by display width, the same way the rest ofbox()already measures. For ASCII titles it returns exactly what the old slice did, so existing snapshots are unchanged; only wide-character titles change behaviour (they now fit the box and the borders stay aligned).No linked issue: this is a small self-contained bug fix.
Type of change
Checklist
pnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure