mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-19 02:12:49 +08:00

The safe height (introduced in 3e2eea730bf0f6fe4a5e336faa312b526d351079) would be 80 (the value of the safe width) instead of 24. Removing the explicit `defaultValue` parameter ensures that the correct constants are used, i.e. Constants.DefaultTerminalWidth and Constants.DefaultTerminalHeight.
53 lines
1.2 KiB
C#
53 lines
1.2 KiB
C#
namespace Spectre.Console;
|
|
|
|
/// <summary>
|
|
/// Represents console output.
|
|
/// </summary>
|
|
public sealed class AnsiConsoleOutput : IAnsiConsoleOutput
|
|
{
|
|
/// <inheritdoc/>
|
|
public TextWriter Writer { get; }
|
|
|
|
/// <inheritdoc/>
|
|
public bool IsTerminal
|
|
{
|
|
get
|
|
{
|
|
if (Writer.IsStandardOut())
|
|
{
|
|
return !System.Console.IsOutputRedirected;
|
|
}
|
|
|
|
if (Writer.IsStandardError())
|
|
{
|
|
return !System.Console.IsErrorRedirected;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public int Width => ConsoleHelper.GetSafeWidth();
|
|
|
|
/// <inheritdoc/>
|
|
public int Height => ConsoleHelper.GetSafeHeight();
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="AnsiConsoleOutput"/> class.
|
|
/// </summary>
|
|
/// <param name="writer">The output writer.</param>
|
|
public AnsiConsoleOutput(TextWriter writer)
|
|
{
|
|
Writer = writer ?? throw new ArgumentNullException(nameof(writer));
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void SetEncoding(Encoding encoding)
|
|
{
|
|
if (Writer.IsStandardOut() || Writer.IsStandardError())
|
|
{
|
|
System.Console.OutputEncoding = encoding;
|
|
}
|
|
}
|
|
} |