Skip to content

ansi: strip SGR sequences with colon-separated parameters - #310

Merged
djc merged 1 commit into
console-rs:mainfrom
yxshee:fix/ansi-colon-params
Nov 9, 2026
Merged

djc merged 1 commit into
console-rs:mainfrom
yxshee:fix/ansi-colon-params

Conversation

@yxshee

@yxshee yxshee commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

strip_ansi_codes (and so measure_text_width, truncate_str, pad_str) only accepts ; between CSI parameters. SGR sequences that use the colon form from ITU T.416, like curly underline \x1b[4:3m or \x1b[38:2::255:128:0m, are cut off after the first number and the rest leaks into the text:

let s = "\x1b[4:3mwavy\x1b[0m \x1b[38:2::255:128:0morange\x1b[0m";
strip_ansi_codes(s)    // ":3mwavy :2::255:128:0morange", expected "wavy orange"
measure_text_width(s)  // 28, expected 11

This lets the parser take : wherever it takes ;, and makes the same change in the reference regex the DFA tests compare against (plus : in the exhaustive small-strings test).

The new strip_sgr_with_colon_separated_params test fails on main with left: ":3mwavy :2::255:128:0morange". make test, make lint and make format-check pass.

@djc djc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@djc
djc merged commit c1220d6 into console-rs:main Nov 9, 2026
20 checks passed
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.

2 participants