You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Forcing ANSI should only be done if you know if you're running inside of a terminal that can handle it. The standard console host (CONHOST), for example, does not support ANSI:
Brad Wilson (@bradwilson) I agree and that's why this is not the default behavior. The default is trying to auto-detect if we can use ansi or not. We then have flags to force using or not using ANSI.
moving to 3.10, I think we need a better design for this, having --ansi and --no-ansi, leads to many combinations with similar options like --no-color and so on.
Jakub Jareš (@nohwnd) what about --ansi <auto|enable|disable>, --color <enable|disable> (this one may need some deps on ansi?).
I think gradle (java) had something interesting where cli has only part of the commands, for extra granularity you needed the config file. Maybe a similar design could help so we don't have to support it all as CLI.
Jakub Jareš (@nohwnd) I moved to "Future" milestone. But feel free to move to "2.0.0" as a breaking change (and if you did, please add it to #5762 and add the "Breaking !!" label)
Given the v2 was missed, what about introducing the new API and deprecating the old ones (but keeping them working)? It feels like something we can implement quickly.
Instead of going into the hassle of deprecations, aligning dotnet test implementation with MTP, etc.. I would suggest keep using the current --no-ansi and updating it such that it accepts one of three values:
auto (same as when omitted --no-ansi is completely omitted): we determine ourselves whether or not to use ansi terminal)
true (same as when --no-ansi is present without an arg): Force non ansi.
false: Force ansi.
Double negation is bad, but this is IMO the approach with the least hassle.
There is actually a 4th mode, simple ANSI. This is what we use in CI to show colors using ANSI, but we cannot move cursor to show progress in-place. This needs more design work.
Given how niche this scenario is, and that in most cases the default behavior will be what the user needs, I think we might simply go with env variables. The proposed flow is:
--no-ansi is still present and is highest precedence. If explicitly passed in command-line, we force-disable ansi. Note: we might still produce colors even in this mode, but we fully rely on Console.ForegroundColor` API in this case (which will still attempt to write ANSI codes on Unix depending on this detection for ANSI, but uses Win32 APIs for changing color under Windows).
Env variable MICROSOFT_TESTING_PLATFORM_ANSI which is either enable, disable, simple.
enable forces use of ANSI terminal (the request in this issue)
disable force disables ANSI terminal (equivalent to --no-ansi)
simple force use of simple ANSI terminal (emits ANSI colors only).
If user didn't specify anything, we fallback to auto detection:
detect CI scenarios where we use simple ANSI.
Otherwise, detect if running environment is ANSI-capable or not.
Alternatively, we could re-use the same env variable as .NET, DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION.
I would also like to understand if the scenario here is about coloring only. In that case it's more of forcing simple ansi, not the full ansi implementation.
Activity
Evangelink commentedon Feb 20, 2025
It's probably a quick and easy update so I don't see why not! Thanks for the suggestion Staffan Gustafsson (@powercode).
cc Mariam Abdullah (@mariam-abdulla) as it might require some porting to
dotnet test.bradwilson commentedon Apr 12, 2025
Forcing ANSI should only be done if you know if you're running inside of a terminal that can handle it. The standard console host (CONHOST), for example, does not support ANSI:
Evangelink commentedon Apr 14, 2025
Brad Wilson (@bradwilson) I agree and that's why this is not the default behavior. The default is trying to auto-detect if we can use ansi or not. We then have flags to force using or not using ANSI.
nohwnd commentedon May 5, 2025
moving to 3.10, I think we need a better design for this, having --ansi and --no-ansi, leads to many combinations with similar options like --no-color and so on.
Evangelink commentedon May 5, 2025
Jakub Jareš (@nohwnd) what about
--ansi <auto|enable|disable>,--color <enable|disable>(this one may need some deps on ansi?).I think gradle (java) had something interesting where cli has only part of the commands, for extra granularity you needed the config file. Maybe a similar design could help so we don't have to support it all as CLI.
bradwilson commentedon May 5, 2025
FWIW, xUnit.net uses
onandofffor switches in MTP. https://github.com/xunit/xunit/blob/main/src/xunit.v3.runner.inproc.console/TestingPlatform/CommandLineOptionsProvider.csnohwnd commentedon May 6, 2025
yes those are all good options, terminal logger does something similar with handling auto, and on/off true/false 0/1.
Then it is just question of deprecating no-ansi no-color or not, but we cannot do that right away anyway.
Youssef1313 commentedon Jul 11, 2025
Jakub Jareš (@nohwnd) I moved to "Future" milestone. But feel free to move to "2.0.0" as a breaking change (and if you did, please add it to #5762 and add the "Breaking !!" label)
Evangelink commentedon Nov 28, 2025
Given the v2 was missed, what about introducing the new API and deprecating the old ones (but keeping them working)? It feels like something we can implement quickly.
Youssef1313 commentedon Jan 8, 2026
Instead of going into the hassle of deprecations, aligning
dotnet testimplementation with MTP, etc.. I would suggest keep using the current--no-ansiand updating it such that it accepts one of three values:auto(same as when omitted--no-ansiis completely omitted): we determine ourselves whether or not to use ansi terminal)true(same as when--no-ansiis present without an arg): Force non ansi.false: Force ansi.Double negation is bad, but this is IMO the approach with the least hassle.
Youssef1313 commentedon Jan 20, 2026
There is actually a 4th mode, simple ANSI. This is what we use in CI to show colors using ANSI, but we cannot move cursor to show progress in-place. This needs more design work.
Given how niche this scenario is, and that in most cases the default behavior will be what the user needs, I think we might simply go with env variables. The proposed flow is:
--no-ansiis still present and is highest precedence. If explicitly passed in command-line, we force-disable ansi. Note: we might still produce colors even in this mode, but we fully rely on Console.ForegroundColor` API in this case (which will still attempt to write ANSI codes on Unix depending on this detection for ANSI, but uses Win32 APIs for changing color under Windows).MICROSOFT_TESTING_PLATFORM_ANSIwhich is eitherenable,disable,simple.enableforces use of ANSI terminal (the request in this issue)disableforce disables ANSI terminal (equivalent to--no-ansi)simpleforce use of simple ANSI terminal (emits ANSI colors only).Youssef1313 commentedon Jan 20, 2026
Alternatively, we could re-use the same env variable as .NET,
DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION.I would also like to understand if the scenario here is about coloring only. In that case it's more of forcing simple ansi, not the full ansi implementation.
Add --ansi <auto|on|off> CLI option for explicit ANSI control
Add --ansi <auto|on|off> CLI option for explicit ANSI control (#5081) (…