cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

allow CLICOLOR_FORCE env var to force CLI color output

Open cconverse711 opened this issue 1 year ago • 10 comments

This adds support for using the CLICOLOR_FORCE environment variable to force color output in Linux even when a tty is not used, mimicking behavior in CMake and other tools. The primary intent is to allow color to be output when cppcheck is run in CI, for example.

cconverse711 avatar Apr 11 '24 04:04 cconverse711

Thanks for your contribution. Please add a unit test for this.

firewave avatar Apr 11 '24 06:04 firewave

Shouldn't this implement NO_COLOR as well?

firewave avatar Apr 11 '24 08:04 firewave

hmm I am not sure if a unit test would be possible. not if getenv is cached. maybe you want to uncache it it testing somehow. or another alternative is to write a test in cppcheck/test/cli/test-other.py

You could add a line in the releasenotes.txt also. And before we merge it it would not hurt if I add a ticket in trac.

danmar avatar Apr 11 '24 08:04 danmar

hmm I am not sure if a unit test would be possible. not if getenv is cached. it might be better to write a test in cppcheck/test/cli/test-other.py

That's actually what I meant. It was still early. 😴

firewave avatar Apr 11 '24 09:04 firewave

Shouldn't this implement NO_COLOR as well?

According to the full linked "proposal", yes, however most of the other tools that support CLICOLOR_FORCE don't actually support NO_COLOR (it seems far less useful, imo). I'm happy to modify the update if you prefer, though.

cconverse711 avatar Apr 11 '24 23:04 cconverse711

According to the full linked "proposal", yes, however most of the other tools that support CLICOLOR_FORCE don't actually support NO_COLOR (it seems far less useful, imo). I'm happy to modify the update if you prefer, though.

I would prefer if you would do both while you are at it.

firewave avatar Apr 12 '24 05:04 firewave

I think your code and testing looks good.

Adding the NO_COLOR sounds easy technically, I am in favor of adding it also :-). But I am not sure how you would add the test for it - ideally the test would provide a tty terminal right?

danmar avatar Apr 12 '24 09:04 danmar

Thanks. I think I figured out a decent way to test using tty, let me know if you'd prefer to omit that.

cconverse711 avatar Apr 12 '24 19:04 cconverse711

I still want to take a look this weekend. Something seems off to me but I cannot tell what.

firewave avatar Apr 26 '24 17:04 firewave

I still want to take a look this weekend. Something seems off to me but I cannot tell what.

Already commented on the "off" thing. Still need to take a look at the Python stuff.

firewave avatar Apr 30 '24 12:04 firewave

Sorry the review took so long.

firewave avatar May 23 '24 12:05 firewave