Skip to content

fix(ansi): Wordwrap breakpoint overflow when line is at limit#814

Open
shuang-liu wants to merge 1 commit into
charmbracelet:mainfrom
shuang-liu:fix/wordwrap-breakpoint-overflow
Open

fix(ansi): Wordwrap breakpoint overflow when line is at limit#814
shuang-liu wants to merge 1 commit into
charmbracelet:mainfrom
shuang-liu:fix/wordwrap-breakpoint-overflow

Conversation

@shuang-liu

@shuang-liu shuang-liu commented Mar 20, 2026

Copy link
Copy Markdown

Wordwrap can produce lines that exceed the configured limit when a breakpoint character (comma, period, semicolon, etc.) appears after text that fills the line to exactly the limit. The breakpoint handling code writes the character and increments curWidth without checking whether the line would overflow.

The Wrap function already handles this correctly by checking curWidth+wordLen >= limit before adding the breakpoint. This commit applies the same pattern to Wordwrap: if the breakpoint would exceed the limit, keep it attached to the preceding word instead of writing it directly to the output.

Applied to both the UTF-8 and ASCII code paths.

[✓] I have read CONTRIBUTING.md https://github.com/charmbracelet/.github/blob/main/CONTRIBUTING.md.
[] I have created a discussion that was approved by a maintainer (for new features).

@shuang-liu shuang-liu force-pushed the fix/wordwrap-breakpoint-overflow branch from 655d71f to c1db9af Compare March 20, 2026 17:10
Wordwrap can produce lines that exceed the configured limit when a
breakpoint character (comma, period, semicolon, etc.) appears after
text that fills the line to exactly the limit. The breakpoint handling
code writes the character and increments curWidth without checking
whether the line would overflow.

The Wrap function already handles this correctly by checking
curWidth+wordLen >= limit before adding the breakpoint. This commit
applies the same pattern to Wordwrap: if the breakpoint would exceed
the limit, keep it attached to the preceding word instead of writing
it directly to the output.

Applied to both the UTF-8 and ASCII code paths.
@shuang-liu shuang-liu force-pushed the fix/wordwrap-breakpoint-overflow branch from c1db9af to 84d6910 Compare March 20, 2026 18:04
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.

1 participant