Skip to content

Conversation

@MazenSamehR
Copy link
Contributor

@MazenSamehR MazenSamehR commented Dec 17, 2025

Summary

Implemented a character-based ANSI-safe wrapper directly in the breakLines function to force deterministic wrapping across all terminals:

  • Implemented internal wrapper: The breakLines function now uses character-based wrapping instead of word-based wrapping

Fixes: #1818

Testing

All existing tests pass. Run:

yarn pretest && yarn test

demo

https://vimeo.com/1147364471?fl=pl&fe=sh

@codecov
Copy link

codecov bot commented Dec 17, 2025

Codecov Report

❌ Patch coverage is 89.28571% with 3 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@67c31c1). Learn more about missing BASE report.

Files with missing lines Patch % Lines
packages/core/src/lib/utils.ts 89.28% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1943   +/-   ##
=======================================
  Coverage        ?   94.75%           
=======================================
  Files           ?       37           
  Lines           ?     1562           
  Branches        ?      456           
=======================================
  Hits            ?     1480           
  Misses          ?       80           
  Partials        ?        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

* @param {number} width
* @return {string}
*/
export function breakLines(content: string, width: number): string {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing here that isn't clear anymore about this approach;

We were talking of how the bug reported seemed to be an issue with how different terminal auto-wrap content and how that conflicted with the cursor position and the way wrap-ansi would do the wrapping.

Given that, it's unclear why a different wrapping algorithm fix this issue. This would fix it for terminals doing simple wraps, but won't it now break for those who're maybe implementing word wrapping instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By implementing character-based wrapping directly in the code rather than relying on wrap-ansi we Make wrapping deterministic, so the exact same wrapping happens on all terminals. So since we control the wrapping, we can accurately calculate cursor positions.

Now a terminal's auto-wrap behavior becomes irrelevant because we've already wrapped the content at exactly width characters, and the terminal receives pre-wrapped lines that fit within its display width. So even if a terminal has word-wrapping enabled, it only applies to content that exceeds the width, which ours won't

Example

Terminal A (word-wrap): "This is a long message"
Terminal B (char-wrap): "This is a long message"

using wrap-ansi:
- Terminal A might wrap: "This is a long" / "message"
- Terminal B might wrap: "This is a lo" / "ng message"
- Cursor calculation broken because we don't know which one we're on!

character-based:
- All terminals receive: "This is a lo" / "ng message"
- Both terminals see it's already wrapped
- Cursor calculation is accurate because we control the wrapping!

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.

Cursor positioning after line wrap

2 participants