-
Notifications
You must be signed in to change notification settings - Fork 45
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
lib: ignore ANSI escape sequences #179
Conversation
@pksunkara, would you be able to do a test with this commit and tell me if this solves your problem in clap-rs/clap#1246? |
This PR will of course not do anything sensible for Windows. As far as I understand, colored text depends on using special Windows APIs and so I guess the color information isn't embedded into the string like on Linux? |
I can't say because we refactored our color writing and we don't construct strings anymore but write directly to |
Aha, I thought based on clap-rs/clap#1246 and #140 (comment) that |
I'll merge it right after I fix Travis -- my crate has again stopped building on Rust 1.31.0. |
Yeah, we will probably need it again when we are fixing clap-rs/clap#1456. But, unfortunately, it is not a priority until after we release 3.0 |
Okay, cool! I'll get a release out of textwrap in the meantime and then I hope it'll be useful for you guys. |
ANSI escape sequences are typically used for colored text. The sequences start with a so-called CSI, followed by some "parameter bytes" before ending with a "final byte". We now handle these escape sequences by simply skipping over the bytes. This works well for escape sequences that change colors since they don't take up space and since they continue to work across any line breaks we insert. See https://en.wikipedia.org/wiki/ANSI_escape_code for details. Fixes: #140.
16851aa
to
827dbe6
Compare
Codecov Report
@@ Coverage Diff @@
## master #179 +/- ##
==========================================
+ Coverage 94.02% 94.19% +0.17%
==========================================
Files 4 4
Lines 368 379 +11
==========================================
+ Hits 346 357 +11
Misses 22 22
Continue to review full report at Codecov.
|
Before you release, do you think you can port this to https://lib.rs/crates/terminal_size? |
Sure, let me update that right away. |
The term_size crate seems unmaintained, as mentioned in #179.
The term_size crate seems unmaintained, as mentioned in #179.
ANSI escape sequences are typically used for colored text. The
sequences start with a so-called CSI, followed by some "parameter
bytes" before ending with a "final byte".
We now handle these escape sequences by simply skipping over the
bytes. This works well for escape sequences that change colors since
they don't take up space and since they continue to work across any
line breaks we insert.
See https://en.wikipedia.org/wiki/ANSI_escape_code for details.
Fixes: #140.