mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 17:02:51 +08:00
Handle output to stderr
This commit is contained in:
parent
9312663bde
commit
a1050fc676
@ -28,7 +28,7 @@ namespace Spectre.Console
|
|||||||
var (supportsAnsi, legacyConsole) = DetectAnsi(settings, buffer);
|
var (supportsAnsi, legacyConsole) = DetectAnsi(settings, buffer);
|
||||||
|
|
||||||
// Use the provided encoding or fall back to UTF-8
|
// Use the provided encoding or fall back to UTF-8
|
||||||
var encoding = buffer.IsStandardOut() ? System.Console.OutputEncoding : Encoding.UTF8;
|
var encoding = buffer.IsStandardOut() || buffer.IsStandardError() ? System.Console.OutputEncoding : Encoding.UTF8;
|
||||||
|
|
||||||
// Get the color system
|
// Get the color system
|
||||||
var colorSystem = settings.ColorSystem == ColorSystemSupport.Detect
|
var colorSystem = settings.ColorSystem == ColorSystemSupport.Detect
|
||||||
@ -73,14 +73,14 @@ namespace Spectre.Console
|
|||||||
// Check whether or not this is a legacy console from the existing instance (if any).
|
// Check whether or not this is a legacy console from the existing instance (if any).
|
||||||
// We need to do this because once we upgrade the console to support ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
// We need to do this because once we upgrade the console to support ENABLE_VIRTUAL_TERMINAL_PROCESSING
|
||||||
// on Windows, there is no way of detecting whether or not we're running on a legacy console or not.
|
// on Windows, there is no way of detecting whether or not we're running on a legacy console or not.
|
||||||
if (AnsiConsole.Created && !legacyConsole && buffer.IsStandardOut() && AnsiConsole.Profile.Capabilities.Legacy)
|
if (AnsiConsole.Created && !legacyConsole && (buffer.IsStandardOut() || buffer.IsStandardError()) && AnsiConsole.Profile.Capabilities.Legacy)
|
||||||
{
|
{
|
||||||
legacyConsole = AnsiConsole.Profile.Capabilities.Legacy;
|
legacyConsole = AnsiConsole.Profile.Capabilities.Legacy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (buffer.IsStandardOut())
|
if (buffer.IsStandardOut() || buffer.IsStandardError())
|
||||||
{
|
{
|
||||||
// Are we running on Windows?
|
// Are we running on Windows?
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
@ -49,6 +49,11 @@ namespace Spectre.Console
|
|||||||
return System.Console.IsOutputRedirected;
|
return System.Console.IsOutputRedirected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_profile.Out.IsStandardError())
|
||||||
|
{
|
||||||
|
return System.Console.IsErrorRedirected;
|
||||||
|
}
|
||||||
|
|
||||||
// Not stdout, so must be a TTY.
|
// Not stdout, so must be a TTY.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -15,5 +15,17 @@ namespace Spectre.Console
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsStandardError(this TextWriter writer)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return writer == System.Console.Error;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ namespace Spectre.Console
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Need to update the output encoding for stdout?
|
// Need to update the output encoding for stdout?
|
||||||
if (_out.IsStandardOut())
|
if (_out.IsStandardOut() || _out.IsStandardError())
|
||||||
{
|
{
|
||||||
System.Console.OutputEncoding = value;
|
System.Console.OutputEncoding = value;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user