-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add option to remove ANSI escape sequences from bat's input. #2999
Conversation
3f81db6
to
87b0c2e
Compare
87b0c2e
to
7724541
Compare
7724541
to
a678878
Compare
Rebased to c264ecd and fixed some clippy warnings. |
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.
Nice work, I'm sure lots of users will find this extra functionality useful
@@ -759,9 +759,14 @@ bat() { | |||
|
|||
If an input file contains color codes or other ANSI escape sequences or control characters, `bat` will have problems | |||
performing syntax highlighting and text wrapping, and thus the output can become garbled. | |||
When displaying such files it is recommended to disable both syntax highlighting and wrapping by | |||
|
|||
If your version of `bat` supports the `--strip-ansi=auto` option, it can be used to remove such sequences |
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.
Interesting idea to add a hint about version in the readme, especially for features not part of a release yet 🙂
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.
It was relevant to the section, and I didn't want to forget to add it later. Had to word it so it didn't seem like it was already available, and that's what I came up with :)
When using `auto`, escape sequences will be stripped unless printing plain text.
a678878
to
90dfa7f
Compare
This pull request introduces a new
--strip-ansi
option tobat
.This option tells
bat
whether to strip ANSI/VT escape sequences from the input file. The following values are supported:always
: Always strip escape sequences.never
: Never strip escape sequences. (default)auto
: Strip escape sequences when printing any language that is not "Plain Text".This preserves bat's ability to print piped commands (or pre-highlighted files) and keep their existing colors.
Benchmarks
Disabled, Regular File
No significant difference.
Enabled, Regular File
A minor reduction in performance.
Disabled, Pre-highlighted File
No significant difference.
Enabled, Pre-highlighted File
It's certainly an improvement.
Auto Mode
The detection part of
--strip-ansi=auto
causes no significant difference when syntax highlighting is used.However, it does add a few milliseconds of startup time when used with
--color=never
. This is because--strip-ansi=auto
relies on detecting the syntax in order to determine if a file is plain text or not (and thus whether to strip the ANSI sequences).TODO
SimplePrinter
(maybe. thoughts?)Wait for Update bat's tab expansion preprocessor to use bat's ANSI escape sequence iterator. #2998.It contains the changes made in b4fe182, which this PR depends on.
Updatelong_help
integration testWrite testsBenchmarksRuncargo fmt
Allow--strip-ansi
to be passed multiple times (so it can be set to auto in config and overridden on the cli)