Repository navigation
Preserve SGR parameter order when mixing colon colors and resets - #321
Closed
anticipate218 wants to merge 1 commit into
Closed
anticipate218 wants to merge 1 commit into
anticipate218 wants to merge 1 commit into
Conversation
Apply accumulated integer SGR parameters before each following colon color. Preserve valid reset/color ordering through the C-backed propagation and clipping APIs, with native and Python regression coverage. Assisted-by: OpenAI Codex
Owner
|
Superseded by #327 |
jquast
added a commit
that referenced
this pull request
Nov 13, 2026
This supersedes #321. I studied kitty and xterm parsing about this small possible deviation from ECMA-48/ITU T.416/etc. standards, and those changes have been simplified (WCWIDTH_SGR_MAX_PARAMS was removed, malloc/realloc/free removed), while also supporting "hybrid" sequences found to be supported in at least xterm and kitty, and it brings coverage of the changed code up to 100% Note that #321 was likely created by AI Analysis, that these are probably [Unlikely sequences](https://github.com/jquast/wcwidth#unlikely-sequences), but, because I discovered code in xterm and kitty that attempts to support them, it is presumed that *some* misbehaving TUI program or library *somewhere* must have drove them into the more complex accommodation.
Author
|
Thanks for reviewing this and consolidating it in #327. I appreciate the xterm/kitty investigation and the simpler allocation-free implementation. Thanks for taking this forward and merging the consolidated fix. |
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.
The C SGR parser applies colon-separated colors immediately, then applies all ordinary parameters afterward. A reset followed by a color, such as
\x1b[0;38:2::255:0:0m, therefore loses its color whenpropagate_sgr()restores it on the next line orclip()restores it at the clipping boundary. The Python implementation already preserves this order.This extracts the existing integer-parameter application loop and flushes each integer run before applying the next colon color. The integer-only path and color serialization are unchanged. Tests cover resets, default/basic colors, and replacement between the two color syntaxes through both public functions and the C library.
The scope is valid SGR parameter sequences. Incomplete color parameters interrupted by a colon tuple can also behave differently; this does not try to define or normalize malformed input.
Validation on Windows x64, CPython 3.13, MSVC:
git diff --check.twine check --strict; the sdist contains the exact tested C source.This was found while reading the SGR parser, rather than from a reported production incident. No real terminal rendering or performance claim is made. AI assistance: OpenAI Codex generated the patch and ran the checks above.