rich: [BUG] v13.3.4 broke coloring
Describe the bug
Previously setting NO_COLOR to 1 would override forced coloring but now it does not. The use case is in CI we force color to get nice test output but inside testing at the beginning of setup we set that environment variable so we can properly assert output.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 33 (18 by maintainers)
Commits related to this issue
- Fix CI https://github.com/Textualize/rich/issues/2924 — committed to DataDog/integrations-core by ofek 4 years ago
This is resolved as of v14 https://github.com/Textualize/rich/pull/3675
Guys, I’m talking about this situation on the ground right now. Not some future where every library and app is consistent.
The current situation is that libraries handle FORCE_COLOR differently. And not just in the Python world. When they implement this env var, they never considered it to be a global thing. It was always a per-app thing, which is likely why there was no agreement on the behavior. That’s why It is objectively a bad idea to set it globally right now, unless you are certain all your apps / libraries conform.
Frankly, I think attempting to retroactively fit this in to some kind of standard, is like King Canute yelling at the tide.
There isn’t a clear description of the problem domain. The word COLOR is forever going to confuse people. Even if it is written down in a “spec”, there will be those that expect bold / italic etc to be included, and those that don’t.
That’s why I’m going to do something I said I wouldn’t, and propose a new environment variable.
TTY_COMPATIBLE. If this is1then we assume we are writing to a TTY like device, even if the app auto-detected otherwise. If it is0then we assume we are not writing to a TTY devices. If it is blank or anything else, then the app should auto detect TTY support.I think this addresses the issue of allowing fancy output in CI.
I concur. The env var would set the default, but any switches implemented by the dev would take precedence.
I think it’s a good proposal. Thanks!
Originally
NO_COLORsaid just the existence of the env var matters, but was updated to explain it should not be empty in https://github.com/jcs/no_color/commit/99f90e27d0fac6a34d07998f8f577e1f2f620c61. We recently updated CPython to match this (https://github.com/python/cpython/pull/129140) and as it happens yesterday opened a PR to update termcolor (https://github.com/termcolor/termcolor/pull/92).One option is to add something like
RICH_COLORS, and you can do whatever you like in that. CPython hasPYTHON_COLORSand pytest hasPY_COLORS, but I can understand not wanting an app-specific solution for Rich.I tend to think
NO_COLORandFORCE_COLORshould also control styles like bold, to enable more control for accessibility reasons, and also piping. But I also understand wanting to follow the “community spec”.It could be worth reviewing how the tools implementing
NO_COLORandFORCE_COLORactually implement it.Perhaps can we ignore precedence and add a new variable that actually disables escape sequences? Or, less desirable,
NO_COLOR=all?