Skip to content

[REQUEST] Enable colours when FORCE_COLOR env var is set #2425

Closed
@hugovk

Description

@hugovk

Have you checked the issues for a similar suggestions?

Yes, initially rejected at #343 but further discussed more favourably at pypa/pip#10909 (comment).

How would you improve Rich?

If the FORCE_COLOR environment variable is set -- to any value -- then enable the use of colour.

(I'm not specifically requesting it here, but could be worth considering: If the NO_COLOR environment variable is set -- to any value -- then disable the use of colour. NO_COLOR should override FORCE_COLOR. Re: https://no-color.org/)

What problem does it solve for you?

What problem do you have that this feature would solve? I may be able to suggest an existing way of solving it.

pip 22 now uses Rich for installation progress bars and some error handling, which gives us pretty colours! And more of pip's interface is being switched over to use Rich for improved usability.

image

Colour can help diagnose problems, and a common place for pip and the need to diagnose problems is on a CI, where you get a big wall of text.

However, because GitHub Actions isn't a tty, output of tools which autodetect the terminal output is usually monochrome. That's why many tools and CI setups use the FORCE_COLOR environment variable, and/or command-line options to turn it back on.

For example, pip's CI (#10830):

https://github.com/pypa/pip/blob/4a508c268ee4be5bc279f1522954b78fa9e25050/.github/workflows/ci.yml#L14-L17

However, Rich doesn't support FORCE_COLOR, meaning we get monochrome output:

image

Compare with nox:

image

https://github.com/pypa/pip/runs/5177210581?check_suite_focus=true

And pytest:

image

https://github.com/pytest-dev/pytest/runs/5185781927?check_suite_focus=true

For reference:

This would benefit not just users of pip, but users of other software which uses Rich as a colour/style library, and mean they do not need to implement it themselves, and Rich would be on par with other colour libraries.

Metadata

Metadata

Assignees

Labels

acceptedTask was acceptedenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions