-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Treat OSC ANSI Sequences as Invisible Text & Add OSC 8 Support #2544
Conversation
a34f6f4
to
bca3a3e
Compare
Made some changes so that we don't need to strip the sequences anymore. Instead, they'll be emitted as-is and just ignored for line wrapping purposes. |
I also found some possible optimizations while doing this:
|
I figured with such a significant change to a hot loop, it might be worth benchmarking I no longer have an Notes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much and sorry for leaving this hanging for so long.
Admittedly, I have not reviewed the very core of this (the escape sequence parser/iterator) in detail, but it looks very reasonable and is well covered by tests.
Also, thank you for performing the benchmarks!
The failed audit check is related to libgit2, which isn't changed by this pull request. Merging this PR. |
This can be used to extract a subset of ANSI escape sequences from a string of text. I have big plans for this eventually, but for now, it'll be used to strip OSC before printing.
This commit strips OSC (Operating System Command) sequences before printing lines. Eventually when time permits, I want to add back support for printing OSC sequences (and improve it to treat hyperlinks like an attribute). Until then, this should help prevent garbled output :)
More specifically, the test ensures that OSC sequences don't end up wrapping the line.
This is an iterator for escape sequences, using EscapeSequenceOffsetsIterator for the underlying parsing of individual escape sequences.
This uses the new EscapeSequenceIterator, saving us a preprocessing step for each line.
Fixes #2541 by
removing OSC sequences from lines before starting to print them.no longer considering ANSI OSC sequences as visible text.Prior to this change, we don't interpret OSC sequences in any special way. They aren't caught by
console::AnsiCodeIterator
, so the OSC sequences were being treated as visible text.When the OSC is printed in full, the terminal would see a valid sequence and hide it. As a consequence, lines would b e wrapped too early.
When the OSC is broken for line wrapping, the terminal wouldn't see a valid sequence. In this case, it prints both halves of the text on different lines and appears to be junk.
Edit: I had some extra time. A couple of new commits gave special handling for the OSC 8 sequence, allowing bat to disable the hyperlink at the end of the line and then re-emit it at the start of the next line.