click icon indicating copy to clipboard operation
click copied to clipboard

Support `FORCE_COLOR` and `NO_COLOR` environment variables

Open ascopes opened this issue 5 months ago • 1 comments

It would be great if the FORCE_COLOR and NO_COLOR environment variables could be used during calls to click.echo/click.secho to determine the default preference for colouring of stdout/stderr when an explicit preference for outputting colour is not set.

It appears that currently, click simply inspects whether the output stream considers itself to be a physical TTY. This is problematic on build systems such as GitLab or Jenkins or GitHub Actions, as logs that could be output in colour will not be since the output stream is still technically a file.

Supporting this would allow simpler catering for outputs that are designed to help visually impaired users when viewing automated build outputs, but may have other applications as well.

These environment variables are a good candidate to be used, because the Python interpreter already considers these specific variables, and other libraries such as colorlog also respect this.

ascopes avatar Jul 30 '25 08:07 ascopes

I made a custom --color/--no-color option flag that supports all variations of the FORCE_COLOR and NO_COLOR environment variables. It is available through my Click Extra project.

Relates to:

  • https://github.com/pallets/click/issues/558
  • https://github.com/pallets/click/issues/1090
  • https://github.com/pallets/click/issues/1498

kdeldycke avatar Aug 03 '25 08:08 kdeldycke