mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-15 00:12:50 +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);
|
||||
|
||||
// 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
|
||||
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).
|
||||
// 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.
|
||||
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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (buffer.IsStandardOut())
|
||||
if (buffer.IsStandardOut() || buffer.IsStandardError())
|
||||
{
|
||||
// Are we running on Windows?
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
|
@ -49,6 +49,11 @@ namespace Spectre.Console
|
||||
return System.Console.IsOutputRedirected;
|
||||
}
|
||||
|
||||
if (_profile.Out.IsStandardError())
|
||||
{
|
||||
return System.Console.IsErrorRedirected;
|
||||
}
|
||||
|
||||
// Not stdout, so must be a TTY.
|
||||
return true;
|
||||
}
|
||||
|
@ -15,5 +15,17 @@ namespace Spectre.Console
|
||||
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?
|
||||
if (_out.IsStandardOut())
|
||||
if (_out.IsStandardOut() || _out.IsStandardError())
|
||||
{
|
||||
System.Console.OutputEncoding = value;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user