dotnet / dotnet/command-line-api

Support for FORCE_COLOR env var

Open
#1,710 9 comments 2 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

Libraries like node's [chalk](https://github.com/chalk/chalk/blob/b17d862944f9efea1ee12aaf80fe19ed5063a34d/source/vendor/supports-color/index.js#L32-L44) and [picocolors](https://github.com/alexeyraspopov/picocolors/blob/6b43e8e83bcfe69ad1391a2bb07239bf11a13bc4/picocolors.js#L3-L9), as well as some popular python projects based on recent discussions, support an env var called `FORCE_COLOR` (and the inverse `NO_COLOR`) to let the user force color output. This is useful for things like CI environments where they support colors but due to running in child processes color support gets disabled ([example of this enabled](https://github.com/OctoLinker/OctoLinker/runs/6043471518?check_suite_focus=true#step:9:44) with jest test output in github actions).

The way this works is when checking to see if the environment supports colors they look for a `FORCE_COLOR` env var and if it's set then color support is enabled regardless of what the environment detection set, or color support is disabled in the case of `NO_COLOR`. Since those two libraries are what most node tools/libraries use a lot of things light up when you enable this which greatly improves looking over build logs for instance.

I tested adding this setting to [one of my projects](https://github.com/xt0rted/dotnet-run-script/pull/24) but I'm now wondering if this is something you'd be interested in supporting in the library directly so all tools using this will benefit from it?

The project I'm testing with is a dotnet equivalent of `npm run ...` so it shows the console output of other tools and would really benefit from .net console libraries supporting this. I'd also just like to see better build log output from `dotnet`.

Examples of my test output can be seen in the build logs here:
- [Without the override](https://github.com/xt0rted/dotnet-run-script/runs/6044119631?check_suite_focus=true#step:5:10)
- [With the override](https://github.com/xt0rted/dotnet-run-script/runs/6044159852?check_suite_focus=true#step:6:11)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.