Skip to content

Windows: Implement a way to enable color in console even when the output is redirected #68340

Open

Description

This is a follow-up to #33980 which was closed as fixed by #47935, but only for Unix/Linux, because Unix and Windows use a different PAL for the tail end of console. The ultimate feature was enabling a new environmental variable: DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION, which when set to 1 or true will still emit color codes when the console is redirected (e.g. under CI conditions for logging).

Here's the Unix PAL implementation (also respecting NO_COLOR):

string? envVar = Environment.GetEnvironmentVariable("DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION");

And here's the Windows PAL: https://github.com/dotnet/runtime/blob/ed04fef3b744ad179f4c570b873721d09534c017/src/libraries/System.Console/src/System/ConsolePal.Windows.cs

Having color output in environments like GitHub Actions is immensely helpful when finding errors in massive logs for example, compare these Unix and Windows runs today (here's an example PR, though the logs will likely expire long-term):

Windows Build (no color)

Linux Build (color!)

The ask is: can we please make DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION work on Windows as well?

cc @0xced @Tyrrrz @stephentoub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions