Skip to content

Improve text wrapping to fill lines completely with ANSI support - #38

Merged
github-actions[bot] merged 1 commit into
masterfrom
claude/info-block-text-wrapping-rl8jbw
Jul 26, 2026
Merged

Improve text wrapping to fill lines completely with ANSI support#38
github-actions[bot] merged 1 commit into
masterfrom
claude/info-block-text-wrapping-rl8jbw

Conversation

@vtempest

Copy link
Copy Markdown
Collaborator

Summary

Replaced the simple block-boundary text wrapping logic with a character-level wrapping algorithm that fills each line completely before moving to the next, even if it means breaking in the middle of an info block. This eliminates wasted space at the end of lines while properly handling ANSI color codes and emoji.

Key Changes

  • Replaced removeAnsiCodes() with wrapAnsiText(): The new function wraps text to a maximum visible width while intelligently handling ANSI escape sequences and emoji surrogate pairs
  • Character-level wrapping: Instead of checking if an entire formatted item fits on the current line, the algorithm now fills each line character-by-character up to the maximum length
  • ANSI code preservation: Color codes are copied verbatim without counting toward line width, and the active color is re-applied at the start of each wrapped line to maintain color continuity across line breaks
  • Emoji handling: Surrogate pairs (emoji) are kept together and correctly counted as width 2
  • Simplified line building: Changed from conditionally appending items to joining all items with spaces and then wrapping the result

Implementation Details

  • The wrapAnsiText() function tracks the active ANSI color state and reapplies it when wrapping to a new line (unless a reset sequence was encountered)
  • ANSI escape sequences are detected by looking for \x1b[ and reading until the trailing m character
  • Emoji detection uses Unicode surrogate pair ranges (0xD800-0xDBFF for high surrogates)
  • The wrapping logic ensures no visible space is wasted at line endings while maintaining proper formatting

https://claude.ai/code/session_01PTMmeo1oiSAEj9vW5UQ2M1

The multi-line output previously wrapped only at info-block boundaries,
pushing an entire block to the next line when it didn't fit and leaving
unused space at the end of each line. Replace that with continuous
character-fill wrapping: each line is filled to line_wrap_length before
breaking, splitting in the middle of a block when needed.

Add wrapAnsiText, which counts visible width (ignoring ANSI escape
sequences), re-applies the active color at the start of each wrapped line
so colors survive a mid-block break, and keeps emoji surrogate pairs
intact. Remove the now-unused removeAnsiCodes helper.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PTMmeo1oiSAEj9vW5UQ2M1
@vercel

vercel Bot commented Jul 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
app-demo Building Building Preview, Comment Jul 26, 2026 8:59pm
appdemo-dev-tools Error Error Jul 26, 2026 8:59pm
appdemo-dev-tools-9bf9 Building Building Preview, Comment Jul 26, 2026 8:59pm
appdemo-dev-tools-9bhw Building Building Preview, Comment Jul 26, 2026 8:59pm
appdemo-dev-tools-a54o Building Building Preview, Comment Jul 26, 2026 8:59pm
appdemo-dev-tools-hxgy Building Building Preview, Comment Jul 26, 2026 8:59pm
appdemo-dev-tools-qz8y Building Building Preview, Comment Jul 26, 2026 8:59pm
cccp-deployment Building Building Preview, Comment Jul 26, 2026 8:59pm

@github-actions
github-actions Bot merged commit 3abed3b into master Jul 26, 2026
5 of 13 checks passed
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.

2 participants