sharkdp / bat

A cat(1) clone with wings.
Apache License 2.0
47.6k stars 1.18k forks source link

Add option to remove ANSI escape sequences from bat's input. #2999

Closed eth-p closed 1 week ago

eth-p commented 2 weeks ago

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:

Benchmarks

Disabled, Regular File

image

No significant difference.

Enabled, Regular File

image

A minor reduction in performance.

Disabled, Pre-highlighted File

image

No significant difference.

Enabled, Pre-highlighted File

image

It's certainly an improvement.

Auto Mode

image

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

image

TODO

eth-p commented 2 weeks ago

Rebased to c264ecd2 and fixed some clippy warnings.