Repository navigation
Conversation
Owner
|
This is only a problem for width 1, no other width? |
Contributor
Author
|
No, it also affects wider widths when the leading whitespace fills the available line. I used width 1 to keep the original examples small. For example, at width 2: wrap('\x1b[31m abc\x1b[0m', 2)
# before: ['\x1b[31m\x1b[0m', '\x1b[31mab\x1b[0m', '\x1b[31mc\x1b[0m']
# after: ['\x1b[31mab\x1b[0m', '\x1b[31mc\x1b[0m']And at width 5: wrap('\x1b[31m hello world\x1b[0m', 5)
# before: ['hello', 'world\x1b[0m']
# after: ['\x1b[31mhello\x1b[0m', '\x1b[31mworld\x1b[0m']The first emits a sequence-only line; the second loses the opening color. I also checked widths 3, 10 and 20. The current patch fixes these without a source change. The regression tests in the PR should cover wider widths too. |
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.
At width 1, leading whitespace combined with SGR sequences can leave a visually empty first line or drop the opening style:
This extends the whitespace-only-line behavior from #292 to styled text. Transfer sequences from a discarded whitespace chunk to the next chunk when there is no current line to receive them. Check visible whitespace before appending a line, retaining sequences for the next chunk instead of emitting a whitespace-only line.
Only perform the additional visible-content scan for lines containing escape sequences, leaving plain-text whitespace on the existing path.
Apply the corresponding change to libwcwidth. Its wrapper intentionally does not propagate SGR per line, so the C tests check its existing raw-sequence behavior rather than Python's default per-line resets.
Tests cover both SGR propagation settings, preserving whitespace when requested, and initial indentation. Six Python regressions fail before the fix; the C regression fails for all three inputs before the fix.
Validation on Linux/Python 3.12.15:
Other Python versions, documentation builds and upstream CI have not been run. No performance improvement is claimed.
Prepared with AI assistance.