Skip to content

Preserve formatting for complete SGR parameter syntax - #144

Open
OskarEichler wants to merge 1 commit into
ku1ik:masterfrom
OskarEichler:codex/rainbow-sgr-parsing
Open

OskarEichler wants to merge 1 commit into
ku1ik:masterfrom
OskarEichler:codex/rainbow-sgr-parsing

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Preserve requested formatting when a string contains an ESC byte outside its initial SGR sequence, and recognize both semicolon and colon SGR parameter forms while wrapping or removing formatting.

Reproduction

On current master, wrapping plain \e[34mblue\e[0m with red returns the string unchanged because the optimized ESC path only inserts after a non-empty initial legacy SGR match. Rainbow.uncolor("\e[38:2::1:2:3mtext\e[m") also leaves the colon-form color sequence.

The updated initial match is anchored with \A, accepts empty parameters such as \e[m, and accepts the colon subparameter syntax documented by xterm's control-sequence reference. Non-SGR control sequences remain untouched. The existing no-ESC fast path is unchanged.

Verification

  • Existing suite: 220 examples, 0 failures on Ruby 3.2.11 and 4.0.6.
  • RuboCop 1.7.0: 15 files, 0 offenses on both Rubies.
  • External model: 1,005 wrapping/uncoloring/immutability checks on each Ruby, including initial/interior/multiline ESC, empty and colon parameters, frozen strings, and non-SGR controls.
  • Rebuilt gem: 14 expected package files, no runtime dependencies, loaded successfully on both Rubies.
  • No test files changed.

Compatibility

No API break. Output changes only for SGR inputs that were previously not wrapped or fully removed as intended.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant