File tree Expand file tree Collapse file tree 3 files changed +14
-10
lines changed Expand file tree Collapse file tree 3 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -14,15 +14,18 @@ private static ConsoleFormatInfo FormatInfoBuilder(IEnvironment environment)
14
14
SupportsAnsiCodes = ConsoleFormatInfo . CurrentInfo . SupportsAnsiCodes ,
15
15
} ;
16
16
17
- if ( consoleFormatProvider . SupportsAnsiCodes )
17
+ if ( environment . GetEnvironmentVariable ( "NO_COLOR" ) is not null )
18
18
{
19
- consoleFormatProvider . SupportsAnsiCodes = environment . GetEnvironmentVariable ( "NO_COLOR" ) is null ;
19
+ consoleFormatProvider . SupportsAnsiCodes = false ;
20
+
21
+ return consoleFormatProvider ;
20
22
}
21
- else
22
- {
23
- var envVar = environment . GetEnvironmentVariable ( "DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION" ) ;
24
23
25
- consoleFormatProvider . SupportsAnsiCodes = envVar is not null && ( envVar == "1" || envVar . Equals ( "true" , StringComparison . OrdinalIgnoreCase ) ) ;
24
+ var envVar = environment . GetEnvironmentVariable ( "DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION" ) ;
25
+
26
+ if ( envVar is not null )
27
+ {
28
+ consoleFormatProvider . SupportsAnsiCodes = envVar == "1" || envVar . Equals ( "true" , StringComparison . OrdinalIgnoreCase ) ;
26
29
}
27
30
28
31
return consoleFormatProvider ;
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ public class ConsoleHelpersTests
16
16
public void FormatInfoBuilder_should_support_NO_COLOR_env_var ( string value )
17
17
{
18
18
// Given
19
- var environment = new TestEnvironment ( isWindows : true ) ;
19
+ var environment = new TestEnvironment ( ) ;
20
20
21
21
environment . SetEnvironmentVariable ( "NO_COLOR" , value ) ;
22
22
@@ -41,7 +41,7 @@ public void FormatInfoBuilder_should_support_NO_COLOR_env_var(string value)
41
41
public void FormatInfoBuilder_should_support_DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION_env_var ( string value , bool expected )
42
42
{
43
43
// Given
44
- var environment = new TestEnvironment ( isWindows : true ) ;
44
+ var environment = new TestEnvironment ( ) ;
45
45
46
46
environment . SetEnvironmentVariable ( "DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION" , value ) ;
47
47
Original file line number Diff line number Diff line change 1
1
namespace RunScript ;
2
2
3
3
using System . Collections ;
4
+ using System . Runtime . InteropServices ;
4
5
5
6
internal class TestEnvironment : IEnvironment
6
7
{
7
8
private readonly Dictionary < string , string ? > _variables = new ( StringComparer . OrdinalIgnoreCase ) ;
8
9
9
- public TestEnvironment ( bool isWindows )
10
+ public TestEnvironment ( bool ? isWindows = null )
10
11
{
11
12
CurrentDirectory = AttributeReader . GetProjectDirectory ( GetType ( ) . Assembly ) ;
12
- IsWindows = isWindows ;
13
+ IsWindows = isWindows ?? RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ;
13
14
}
14
15
15
16
public string CurrentDirectory { get ; }
You can’t perform that action at this time.
0 commit comments