This pull request introduces a new --strip-ansi option to bat.
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
Support stripping sequences in SimplePrinter (maybe. thoughts?)
~~Wait for #2998.
It contains the changes made in b4fe182960e45d4fd9ebd5ac2c4d2e4b4522b144, which this PR depends on.~~
Update long_help integration test
Write tests
Benchmarks
Run cargo fmt
Allow --strip-ansi to be passed multiple times (so it can be set to auto in config and overridden on the cli)
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?)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)