Browse Source

Refactore console extensions (#822)

* use of language feature

* removed intend if

* replaced ifs with switch

* Update ConsoleExtensions.cs

Co-authored-by: John Luo <johluo@microsoft.com>
finitereality/replica-status-colors
Marvin Huber 6 years ago
committed by GitHub
parent
commit
75a731b656
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      src/Microsoft.Tye.Core/ConsoleExtensions.cs

36
src/Microsoft.Tye.Core/ConsoleExtensions.cs

@ -14,18 +14,20 @@ namespace System.CommandLine
{
get
{
if (_isConsoleRedirectionCheckSupported == null)
if (_isConsoleRedirectionCheckSupported != null)
{
try
{
var check = Console.IsOutputRedirected;
_isConsoleRedirectionCheckSupported = true;
}
return _isConsoleRedirectionCheckSupported.Value;
}
try
{
var check = Console.IsOutputRedirected;
_isConsoleRedirectionCheckSupported = true;
}
catch (PlatformNotSupportedException)
{
_isConsoleRedirectionCheckSupported = false;
}
catch (PlatformNotSupportedException)
{
_isConsoleRedirectionCheckSupported = false;
}
return _isConsoleRedirectionCheckSupported.Value;
@ -39,12 +41,7 @@ namespace System.CommandLine
((dynamic)console).ForegroundColor = color;
}
if (IsConsoleRedirectionCheckSupported &&
!Console.IsOutputRedirected)
{
Console.ForegroundColor = color;
}
else if (IsConsoleRedirectionCheckSupported)
if (IsConsoleRedirectionCheckSupported)
{
Console.ForegroundColor = color;
}
@ -57,12 +54,7 @@ namespace System.CommandLine
((dynamic)console).ForegroundColor = ConsoleColor.Red;
}
if (IsConsoleRedirectionCheckSupported &&
!Console.IsOutputRedirected)
{
Console.ResetColor();
}
else if (IsConsoleRedirectionCheckSupported)
if (IsConsoleRedirectionCheckSupported)
{
Console.ResetColor();
}

Loading…
Cancel
Save