Skip to content

Fix truncation exceeding maxWidth for wide characters#29

Closed
RyogaK wants to merge 1 commit into
sindresorhus:mainfrom
RyogaK:fix/cjk-truncate-width
Closed

Fix truncation exceeding maxWidth for wide characters#29
RyogaK wants to merge 1 commit into
sindresorhus:mainfrom
RyogaK:fix/cjk-truncate-width

Conversation

@RyogaK

@RyogaK RyogaK commented Apr 3, 2026

Copy link
Copy Markdown

Summary

Test plan

  • Added test that verifies stringWidth(result) <= maxWidth for all widths 1–25 across all three positions with CJK input
  • All existing tests pass

sliceAnsi rounds up when the slice boundary falls inside a wide (CJK)
character, causing the result to exceed the specified columns.
Add a safeSliceAnsi wrapper that re-slices with a 1-column narrower
range when this happens.

Workaround for chalk/slice-ansi#43
Fixes #28
@RyogaK

RyogaK commented Apr 3, 2026

Copy link
Copy Markdown
Author

CI failure is unrelated to this PR — xo now flags @typescript-eslint/no-unnecessary-type-arguments in index.test-d.ts, which exists on main as well. Likely a newer xo or typescript-eslint version in CI picked up the rule.

@RyogaK

RyogaK commented Apr 3, 2026

Copy link
Copy Markdown
Author

Opened #30 to fix the xo lint error.

The main branch itself is currently failing CI due to a transitive dependency issue (see #31). @sindresorhus could you address that first when you get a chance? This PR's CI can't pass until then.

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.

Truncation exceeds maxWidth for East Asian wide characters

1 participant