Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 11, 2025

Implementation Plan for --ansi option

  • Update TerminalTestReporterCommandLineOptionsProvider to add new --ansi option with argument arity of exactly one
  • Add validation logic for --ansi option to accept: auto, on, true, enable, 1, off, false, disable, 0
  • Add localization resource strings for the new option description and validation error messages
  • Update all .xlf files with new localization entries
  • Update TerminalOutputDevice to parse and use the new --ansi option value
  • Ensure backward compatibility: keep --no-ansi working as before
  • Add unit tests for the new option validation
  • Add integration tests to verify the new option behavior
  • Update PublicAPI.Unshipped.txt if needed
  • Address code review feedback - properly handle force enable/disable modes
  • Build and test the changes (build server has network issues, but syntax validated)
  • Run code review - PASSED ✓
  • Run security scan - PASSED ✓
  • Address all PR feedback:
    • Add reusable CommandLineOptionArgumentValidator for on/off/auto validation
    • Add obsolescence support to CommandLineOption with message parameter
    • Mark --no-ansi as obsolete with suggestion to use --ansi off
    • Update descriptions to be clearer (list primary values first, then aliases)
    • Optimize validator to avoid array allocations
    • Add generic boolean validator (IsValidBooleanArgument) for options without auto mode
    • Rename to more descriptive names (IsValidBooleanAutoArgument)
    • Update description to multiline format for better readability
    • Update all xlf files with multiline descriptions
    • Remove duplicate ObsolescenceMessage and IsObsolete from Equals/GetHashCode
    • Remove unused constant values for individual arguments
    • Remove unnecessary wrapper methods in TerminalOutputDevice
    • Introduce enum to replace bool? ForceAnsi for clarity
    • Remove unnecessary customization parameters from validator methods
    • Rename enum to generic and reusable with On/Off/Auto values
    • Rename to ActivationMode for semantic clarity

Summary

Successfully implemented the --ansi option with the following behavior:

  • --ansi auto (default): Auto-detect terminal capabilities
  • --ansi on|true|enable|1: Force enable ANSI output (even when redirected)
  • --ansi off|false|disable|0: Force disable ANSI output
  • --no-ansi: Backward compatible, marked as obsolete with suggestion to use --ansi off

All tests added, code review passed, no security issues found. All PR feedback addressed including:

  • Generic helpers for boolean and boolean+auto validation (reusable for other options like --no-progress)
  • Multiline description format for clarity
  • Cleaned up duplicate properties and unused constants
  • Direct use of helper methods instead of wrapper methods
  • ActivationMode enum (Auto/On/Off) in CommandLine namespace - semantic, clear, and reusable for any activation-based option
  • Simplified validator methods by removing unused customization parameters
Original prompt

This section details on the original issue you should resolve

<issue_title>Add --ansi option to force Ansi output</issue_title>
<issue_description>## Summary

Add the complement to --no-ansi, that forces --ansi output, even if output is redirected.

Background and Motivation

When running the tests from a PowerShell script, I may want to display the test output but not have it as output from the PowerShell function.

mytest.exe | Out-Host
if ($LASTEXITCODE){
   throw "test failed"
}

This removes all coloring from the output, even though it's logically equivalent to passing it directly to the terminal for display.

Proposed Feature

Add --ansi parameter that forces ansi output, regardless of redirection. Let the user decide.

Alternative Designs

Always output ansi unless the user explicitly uses --no-ansi.
That has the drawback of potentially breaking existing scripts.
</issue_description>

<agent_instructions>Let's introduce a new option called --ansi that can take the following values:

  • auto the default
  • on, true, enable, 1 -> enable/force enabling ansi
  • off, false, disable, 0 -> disable ansi
    </agent_instructions>

Comments on the Issue (you are @copilot in this section)

@Evangelink It's probably a quick and easy update so I don't see why not! Thanks for the suggestion @powercode.

cc @mariam-abdulla as it might require some porting to dotnet test.</comment_new>
<comment_new>@Evangelink
@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.</comment_new>
<comment_new>@nohwnd
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.</comment_new>
<comment_new>@Evangelink
@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.</comment_new>
<comment_new>@nohwnd
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.</comment_new>
<comment_new>@Youssef1313
@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)</comment_new>
<comment_new>@Evangelink
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.</comment_new>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits December 11, 2025 14:09
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI changed the title [WIP] Add --ansi option to force Ansi output Add --ansi option for explicit ANSI control Dec 11, 2025
Copilot AI requested a review from Evangelink December 11, 2025 14:20
Copilot AI and others added 2 commits December 12, 2025 16:39
…d clearer descriptions

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
# Conflicts:
#	src/Platform/Microsoft.Testing.Platform/CommandLine/CommandLineOption.cs
#	src/Platform/Microsoft.Testing.Platform/PublicAPI/PublicAPI.Unshipped.txt
…format

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested a review from Evangelink December 12, 2025 16:53
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
…umentValidator

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copy link
Member

@nohwnd nohwnd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just comments that you don't have to address.

@nohwnd nohwnd disabled auto-merge December 18, 2025 13:45
Copy link
Member

@nohwnd nohwnd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^^^

@Evangelink Evangelink enabled auto-merge (squash) December 18, 2025 15:18
@Evangelink Evangelink closed this Dec 19, 2025
auto-merge was automatically disabled December 19, 2025 12:38

Pull request was closed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --ansi option to force Ansi output

3 participants