Fix IndexError in Strings::Wrap.wrap and correct ANSI color insertion on wrap
#23
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?