mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-12-29 12:05:47 +08:00
Add output abstraction and reorganize profile
* Moves ColorSystem from Profile to Capabilities * Renames Tty to IsTerminal * Adds IAnsiConsoleOutput to make output more flexible Closes #343 Closes #359 Closes #369
This commit is contained in:
committed by
Phil Scott
parent
bc9f610258
commit
3e2eea730b
@@ -7,7 +7,12 @@ namespace Spectre.Console
|
||||
/// </summary>
|
||||
public sealed class Capabilities : IReadOnlyCapabilities
|
||||
{
|
||||
private readonly Profile _profile;
|
||||
private readonly IAnsiConsoleOutput _out;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color system.
|
||||
/// </summary>
|
||||
public ColorSystem ColorSystem { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not
|
||||
@@ -33,26 +38,10 @@ namespace Spectre.Console
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether or not
|
||||
/// console output has been redirected.
|
||||
/// the output is a terminal.
|
||||
/// </summary>
|
||||
public bool Tty
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_profile.Out.IsStandardOut())
|
||||
{
|
||||
return System.Console.IsOutputRedirected;
|
||||
}
|
||||
|
||||
if (_profile.Out.IsStandardError())
|
||||
{
|
||||
return System.Console.IsErrorRedirected;
|
||||
}
|
||||
|
||||
// Not stdout, so must be a TTY.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
[Obsolete("Use Profile.Out.IsTerminal instead")]
|
||||
public bool IsTerminal => _out.IsTerminal;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether
|
||||
@@ -67,11 +56,12 @@ namespace Spectre.Console
|
||||
public bool Unicode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Capabilities"/> class.
|
||||
/// Initializes a new instance of the
|
||||
/// <see cref="Capabilities"/> class.
|
||||
/// </summary>
|
||||
internal Capabilities(Profile profile)
|
||||
internal Capabilities(IAnsiConsoleOutput @out)
|
||||
{
|
||||
_profile = profile ?? throw new ArgumentNullException(nameof(profile));
|
||||
_out = @out ?? throw new ArgumentNullException(nameof(@out));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user