Refactor ANSI handling for better readability#7245
Merged
Evangelink merged 2 commits intomainfrom Jan 16, 2026
Merged
Conversation
7e73c65 to
7ef3e8b
Compare
Evangelink
approved these changes
Jan 16, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors ANSI handling from three boolean properties (UseAnsi, ForceAnsi, UseCIAnsi) to a single enum property (AnsiMode) with four clearly defined values, significantly improving code clarity and maintainability.
Changes:
- Introduced
AnsiModeenum with four values:NoAnsi,SimpleAnsi,AnsiIfPossible, andForceAnsi - Refactored
TerminalTestReporterOptionsto use the newAnsiModeenum instead of three boolean properties - Updated
TerminalTestReporterconstructor logic to handle the new enum-based approach - Updated
TerminalOutputDeviceto set the appropriateAnsiModebased on command-line options and CI detection - Updated all test cases to use the new
AnsiModeenum values
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporterOptions.cs | Replaced three boolean properties with a single AnsiMode enum property; added the AnsiMode enum with four well-documented values |
| src/Platform/Microsoft.Testing.Platform/OutputDevice/Terminal/TerminalTestReporter.cs | Refactored constructor logic to use AnsiMode enum with cleaner conditional flow |
| src/Platform/Microsoft.Testing.Platform/OutputDevice/TerminalOutputDevice.cs | Updated initialization logic to determine and set the appropriate AnsiMode based on command-line options and CI detection |
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs | Updated all test cases to use the new AnsiMode enum values instead of multiple boolean properties |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Keeping three boolean properties for ANSI handling (UseAnsi, ForceAnsi, UseCIAnsi) is IMO unnecessarily complicated. It creates 8 possible combinations, while in reality we have just 4 possibilities (one of them is test-only).
This refactors the three properties to be a single property of a new enum type that can be
NoAnsi,SimpleAnsi,AnsiIfPossible,ForceAnsi.NoAnsi: disable both coloring and cursor movement. User requests it explicitly via--no-ansiSimpleAnsi: enables only coloring. Used in CI, unless the user specifies--no-ansi.AnsiIfPossible: Enables both coloring and cursor movement, but only if we detect that the terminal is capable.ForceAnsi: Used only by unit tests. Force-enables coloring and cursor movement, even if terminal isn't capable.