sharkdp / bat

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

--force-colorization does not work for --help #2778

Open xeruf opened 10 months ago

xeruf commented 10 months ago

What steps will reproduce the bug?

bat --help --force-colorization | cat

What happens?

No content formatting

What did you expect to happen instead?

flags are bold like when unpiped

How did you install bat?

Arch

bat version and environment

bat -V bat 0.24.0 (fc954685)

eth-p commented 7 months ago

Great catch! I'm not really sure this is something that would be easy to fix, though.

bat uses clap for argument parsing and generating the --help message. By default, clap will only print the help message in color when printing to a terminal/tty. And in order to override clap's behaviour and force the help message to be colored, we would need to parse the --force-colorization argument using clap—which is a chicken and egg problem.

I suppose we could parse the arguments twice, but I don't feel like that's a good use of processing time for something that doesn't occur often and doesn't affect the user experience in a major way.

sharkdp commented 7 months ago

And in order to override clap's behaviour and force the help message to be colored, we would need to parse the --force-colorization argument using clap—which is a chicken and egg problem.

We actually do this already:

https://github.com/sharkdp/bat/blob/3761df9112e8cad0b2afca49dcea7d847f1a99f6/src/bin/bat/app.rs#L59

So it might not be too hard to fix. But I agree that it doesn't necessarily require fixing. --force-colorization is about bats standard output, not its --help text.