Fix IndexError in Strings::Wrap.wrap and correct ANSI color insertion on wrap#23
Open
onk wants to merge 3 commits intopiotrmurach:masterfrom
Open
Fix IndexError in Strings::Wrap.wrap and correct ANSI color insertion on wrap#23onk wants to merge 3 commits intopiotrmurach:masterfrom
Strings::Wrap.wrap and correct ANSI color insertion on wrap#23onk wants to merge 3 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.
5 tasks
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.
Describe the change
When wrapping lines, reset the insertion index of carried-over ANSI codes to 0 so that they are always applied at the start of the new line.
This probably fixes #4 and #16.
Why are we doing this?
1. Prevent IndexError
When an ANSI code appeared at the end of a line, and the wrapped remainder of the text was shorter, the code was reinserted at an out-of-range position on the next line, causing an IndexError. Resetting the insertion position resolves this issue.
Repro:
2. Preserve ANSI stack when reapplying colors
insert_ansikept using the original insert index from the previous line, so carry-over codes without resets were reinserted at the wrong position.Resetting every pending entry to
[code, 0]to be applied at the line start, which prevents misplaced inserts and lets nested codes line up correctly.Repro:
Expected:
Actual:
Benefits
IndexErrorcaused by reinserting ANSI codes past string boundariesDrawbacks
Requirements
masterbranch?