-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add FORCE_COLOR environment variable support #124107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
232fb67
Add FORCE_COLOR environment variable support
kasperk81 211984d
Test FORCE_COLOR and NO_COLOR
kasperk81 b742c36
Add to ConsoleLoggerProvider
kasperk81 3457d64
Optimize assertions in Color test
kasperk81 c765ed4
Fix XML comments for ANSI color code methods
kasperk81 6b04468
Reorder
kasperk81 e8ce1dd
space
kasperk81 2fb7583
Combine mutiple variables
kasperk81 98d6829
Combined
kasperk81 dd61e36
Fix formatting
kasperk81 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,8 +67,9 @@ public static void RedirectedOutputDoesNotUseAnsiSequences() | |
| Console.ResetColor(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests for System.Console. What about for M.E.Logging.Console? Also, these tests are only validating a single env var. Can we have a few tests that validate when multiple env vars are set and thus their precedence? |
||
| Console.Write('4'); | ||
|
|
||
| Assert.Equal(0, Encoding.UTF8.GetString(data.ToArray()).ToCharArray().Count(c => c == Esc)); | ||
| Assert.Equal("1234", Encoding.UTF8.GetString(data.ToArray())); | ||
| string output = Encoding.UTF8.GetString(data.ToArray()); | ||
| Assert.Equal(0, output.ToCharArray().Count(c => c == Esc)); | ||
| Assert.Contains("1234", output); | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -78,16 +79,25 @@ public static bool TermIsSetAndRemoteExecutorIsSupported | |
| [ConditionalTheory(nameof(TermIsSetAndRemoteExecutorIsSupported))] | ||
| [PlatformSpecific(TestPlatforms.AnyUnix)] | ||
| [SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Not supported on Browser, iOS, MacCatalyst, or tvOS.")] | ||
| [InlineData(null)] | ||
| [InlineData("1")] | ||
| [InlineData("true")] | ||
| [InlineData("tRuE")] | ||
| [InlineData("0")] | ||
| [InlineData("false")] | ||
| public static void RedirectedOutput_EnvVarSet_EmitsAnsiCodes(string? envVar) | ||
| [InlineData("DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION", null, false)] | ||
| [InlineData("DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION", "1", true)] | ||
| [InlineData("DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION", "true", true)] | ||
| [InlineData("DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION", "tRuE", true)] | ||
| [InlineData("DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION", "0", false)] | ||
| [InlineData("DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION", "false", false)] | ||
| [InlineData("FORCE_COLOR", "1", true)] | ||
| [InlineData("FORCE_COLOR", "true", true)] | ||
| [InlineData("FORCE_COLOR", "any-value", true)] | ||
| [InlineData("NO_COLOR", "1", false)] | ||
| [InlineData("NO_COLOR", "true", false)] | ||
| [InlineData("NO_COLOR", "any-value", false)] | ||
| public static void RedirectedOutput_EnvironmentVariableSet_RespectColorPreference(string envVarName, string? envVarValue, bool shouldEmitEscapes) | ||
| { | ||
| var psi = new ProcessStartInfo { RedirectStandardOutput = true }; | ||
| psi.Environment["DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION"] = envVar; | ||
| if (envVarValue is not null) | ||
| { | ||
| psi.Environment[envVarName] = envVarValue; | ||
| } | ||
|
|
||
| for (int i = 0; i < 3; i++) | ||
| { | ||
|
|
@@ -113,13 +123,11 @@ public static void RedirectedOutput_EnvVarSet_EmitsAnsiCodes(string? envVar) | |
|
|
||
| using RemoteInvokeHandle remote = RemoteExecutor.Invoke(main, i.ToString(CultureInfo.InvariantCulture), new RemoteInvokeOptions() { StartInfo = psi }); | ||
|
|
||
| bool expectedEscapes = envVar is not null && (envVar == "1" || envVar.Equals("true", StringComparison.OrdinalIgnoreCase)); | ||
|
|
||
| string stdout = remote.Process.StandardOutput.ReadToEnd(); | ||
| string[] parts = stdout.Split("SEPARATOR"); | ||
| Assert.Equal(3, parts.Length); | ||
|
|
||
| Assert.Equal(expectedEscapes, parts[1].Contains(Esc)); | ||
| Assert.Equal(shouldEmitEscapes, parts[1].Contains(Esc)); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.