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

Most upvoted comments

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 is 1 then we assume we are writing to a TTY like device, even if the app auto-detected otherwise. If it is 0 then 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.

  • It doesn’t have the confusion of what COLOR means. Having the COLOR in FORCE_COLOR means something different than NO_COLOR is nasty, and we should avoid it.
  • The naming says what it does.
  • It’s not currently used anywhere I am aware of.
  • It can be universal, so we don’t need a variable per app / library.

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!

Even the libraries on force-color.org don’t agree. On some FORCE_COLOR=0 means no color, and others it means enable color.

I just double-checked, and both force-color.org and no-color.org say that the respective env var values should be non-empty. It’s not just the env var presence. I imagine that somebody implementing this for the first time will just follow that. If Rich decided to follow the same recommendations, it’d probably address our concern as well.

It might be valuable to hear from @hugovk who’s been advocating for FORCE_COLOR + NO_COLOR support for years and also implemented it in termcolor.

Originally NO_COLOR said 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 has PYTHON_COLORS and pytest has PY_COLORS, but I can understand not wanting an app-specific solution for Rich.

I tend to think NO_COLOR and FORCE_COLOR should 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_COLOR and FORCE_COLOR actually implement it.

Perhaps can we ignore precedence and add a new variable that actually disables escape sequences? Or, less desirable, NO_COLOR=all?