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

Loading…
Cancel
Save