Skip to content

Strip OSC and DCS sequences to support e.g. OSC 8 hyperlinks over tmux. - #280

Merged
djc merged 1 commit into
console-rs:mainfrom
khoek:main
Aug 13, 2026
Merged

djc merged 1 commit into
console-rs:mainfrom
khoek:main

Conversation

@khoek

@khoek khoek commented Feb 7, 2026 •

Copy link
Copy Markdown
Contributor

I noticed that using indicatif (and friends) to embed a hyperlink in a console progress bar caused the wheels to fall off my app (with many newlines being spammed to the console and the auto-updating line-rewriting broken). I tracked the problem down to the OSC sequences incorrectly being interpreted as printable, and the following patch fixes the problem for me.

@djc

djc commented Feb 7, 2026 •

Copy link
Copy Markdown
Member

Appreciate the clean commit history, but it looks like there's a fair bit of code duplication. Could that be deduplicated? (If not, why not?)

@khoek

khoek commented Feb 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Appreciate the clean commit history, but it looks like there's a fair bit of code duplication. Could that be deduplicated? (If not, why not?)

@djc Just my editorial choice to keep things simple. Did you have something more like the following (see latest commit) in mind? It's more complex but clarifies intent. (Happy to squash if you like it, honestly I kind of do.)

Either way, I think the new commit at least clearly shows why there is some subtlety due to the differences in OSC and DCS semantics/idiosyncrasies---two examples:

  • \x07 (BEL) is allowed to close an OSC sequence without needing ESC \
  • ESC \ ends both OSC and DSC, and for recovery we allow ESC EOF to terminated, but in DSC there are also escaped ESC ESCs so one needs to be sure this doesn't break ESC EOF handling.

Let me know what you like!

@khoek
khoek force-pushed the main branch 2 times, most recently from 3d2f8f2 to 07d3b28 Compare February 8, 2026 02:11
@khoek

khoek commented Feb 8, 2026

Copy link
Copy Markdown
Contributor Author

(Sorry about the noise I was bikeshedding a function name.)

@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.

I definitely like it better too -- please squash.

Is there existing stuff which could leverage the same trait?

Comment thread src/ansi.rs
Comment thread src/ansi.rs Outdated
@khoek

khoek commented Feb 13, 2026

Copy link
Copy Markdown
Contributor Author

If there's a natural other place the same trait fits, I can't seem to find it. I would say the DFA core is structurally a bit different.

(Above are my subjective feelings about your comments and they are made with relatively little conviction, so please feel free to override if you feel more strongly.)

@khoek

khoek commented Feb 24, 2026

Copy link
Copy Markdown
Contributor Author

@djc (The politest possible) ping, just in case this fell off your desk (as opposed to being placed in the filing cabinet 😄). Obviously no pressure.

@djc

djc commented Feb 24, 2026 •

Copy link
Copy Markdown
Member

I'll have you know my GitHub notifications are neatly stacked in a filing cabinet 😄, but due to various factors (including vacation) the cabinet is rather full at the moment -- ping me again if I haven't gotten to it in a month, okay?

@khoek

khoek commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

@djc polite ping! :)

@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 for your patience! This needs a rebase and a few more tweaks.

Comment thread src/ansi.rs
Comment thread src/ansi.rs Outdated
Comment thread src/ansi.rs Outdated
Treat OSC and DCS control strings, including tmux passthrough wrappers, as non-printing when iterating or stripping ANSI codes. Include the Zellij fixture in packaged sources for the parser regression tests.
@khoek

khoek commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor Author

@djc Rebased onto current main, squashed to one commit, and (I believe) addressed both remaining inline suggestions. Sorry about falling off the face of the earth!

@djc
djc merged commit 97a91ae into console-rs:main Aug 13, 2026
20 checks passed
@djc

djc commented Aug 13, 2026

Copy link
Copy Markdown
Member

Thanks!

@djc

djc commented Aug 13, 2026

Copy link
Copy Markdown
Member

Released in 0.16.5.

kodiakhq Bot pushed a commit to pdylanross/fatigue that referenced this pull request Sep 14, 2026
Bumps console from 0.16.4 to 0.16.6.

Release notes
Sourced from console's releases.

0.16.6
What's Changed

Fix truncate_str panicking mid-character without ansi-parsing by @​lenamonj in console-rs/console#296
perf: accelerate printable ASCII text width by @​dexhunter in console-rs/console#297
fix: measure the truncation tail in visible columns, not raw width by @​youdie006 in console-rs/console#298
Prepare 0.16.6 by @​djc in console-rs/console#299

0.16.5
What's Changed

Strip OSC and DCS sequences to support e.g. OSC 8 hyperlinks over tmux. by @​khoek in console-rs/console#280




Commits

4329b77 Bump version to 0.16.6
bdf46b0 utils: wrap tests in module
4f54213 fix: measure the truncation tail in visible columns
ed342d0 test: consolidate text width regression coverage
48b99e9 perf: accelerate printable ASCII text width
abf0358 Fix truncate_str panicking mid-character without ansi-parsing
ac3cb73 Bump version to 0.16.5
97a91ae ansi: strip OSC and DCS sequences
See full diff in compare view




Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


Dependabot commands and options

You can trigger Dependabot actions by commenting on this PR:

@dependabot rebase will rebase this PR
@dependabot recreate will recreate this PR, overwriting any edits that have been made to it
@dependabot show <dependency name> ignore conditions will show all of the ignore conditions of the specified dependency
@dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
@dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
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