Track unclosed ANSI sequences to preserve correct color state across wraps#24
Closed
onk wants to merge 5 commits intopiotrmurach:masterfrom
Closed
Track unclosed ANSI sequences to preserve correct color state across wraps#24onk wants to merge 5 commits intopiotrmurach:masterfrom
onk wants to merge 5 commits intopiotrmurach:masterfrom
Conversation
Fixes an IndexError raised when an ANSI code starts at the end of a wrapped line and carries over to a shorter next line. The carry-over kept the original column index, so insert_ansi tried to insert beyond the new string length. Normalize carried-over ANSI entries to [code, 0] so they always reapply at the beginning of the next line.
onk
commented
Nov 9, 2025
| expect(val).to eq([ | ||
| "\e[32mone\e[0m", | ||
| "\e[33mtwo\e[0m", | ||
| "\e[32m\e[33mtwo\e[0m\e[0m", |
Previously a boolean flag (`matched_reset`) was used, which failed when multiple reset codes appeared. Replacing it with a counter (`pending_resets`) allows nested ANSI states to unwind correctly during line wrapping.
3d6fef5 to
29c2d43
Compare
Author
|
While continuing the work, I realised that the underlying ANSI wrap logic needs a broader reconsideration than I initially expected. I’d like to revisit the approach more systematically, so I will close this PR for now and return with a revised version. |
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.
Please review after #23.
Describe the change
The wrapping logic now tracks the count of unclosed ANSI sequences rather than using a boolean flag.
This allows multiple or nested ANSI codes to be preserved correctly when text is wrapped across lines.
Why are we doing this?
Benefits
Drawbacks
Requirements
masterbranch?