mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-07-06 04:28:15 +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
@ -33,7 +33,7 @@ namespace Spectre.Console.Testing
|
||||
{
|
||||
Ansi = ansi,
|
||||
ColorSystem = (ColorSystemSupport)colors,
|
||||
Out = _writer,
|
||||
Out = new AnsiConsoleOutput(_writer),
|
||||
Enrichment = new ProfileEnrichment
|
||||
{
|
||||
UseDefaultEnrichers = false,
|
||||
|
@ -2,13 +2,15 @@ namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class FakeCapabilities : IReadOnlyCapabilities
|
||||
{
|
||||
public ColorSystem ColorSystem { get; set; } = ColorSystem.TrueColor;
|
||||
|
||||
public bool Ansi { get; set; }
|
||||
|
||||
public bool Links { get; set; }
|
||||
|
||||
public bool Legacy { get; set; }
|
||||
|
||||
public bool Tty { get; set; }
|
||||
public bool IsTerminal { get; set; }
|
||||
|
||||
public bool Interactive { get; set; }
|
||||
|
||||
|
@ -16,7 +16,7 @@ namespace Spectre.Console.Testing
|
||||
public RenderPipeline Pipeline { get; }
|
||||
|
||||
public FakeConsoleInput Input { get; }
|
||||
public string Output => Profile.Out.ToString();
|
||||
public string Output => Profile.Out.Writer.ToString();
|
||||
public IReadOnlyList<string> Lines => Output.TrimEnd('\n').Split(new char[] { '\n' });
|
||||
|
||||
public FakeConsole(
|
||||
@ -28,10 +28,10 @@ namespace Spectre.Console.Testing
|
||||
ExclusivityMode = new FakeExclusivityMode();
|
||||
Pipeline = new RenderPipeline();
|
||||
|
||||
Profile = new Profile(new StringWriter(), encoding ?? Encoding.UTF8);
|
||||
Profile = new Profile(new AnsiConsoleOutput(new StringWriter()), encoding ?? Encoding.UTF8);
|
||||
Profile.Width = width;
|
||||
Profile.Height = height;
|
||||
Profile.ColorSystem = colorSystem;
|
||||
Profile.Capabilities.ColorSystem = colorSystem;
|
||||
Profile.Capabilities.Ansi = supportsAnsi;
|
||||
Profile.Capabilities.Legacy = legacyConsole;
|
||||
Profile.Capabilities.Interactive = interactive;
|
||||
@ -41,7 +41,7 @@ namespace Spectre.Console.Testing
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Profile.Out.Dispose();
|
||||
Profile.Out.Writer.Dispose();
|
||||
}
|
||||
|
||||
public void Clear(bool home)
|
||||
@ -52,7 +52,7 @@ namespace Spectre.Console.Testing
|
||||
{
|
||||
foreach (var segment in renderable.GetSegments(this))
|
||||
{
|
||||
Profile.Out.Write(segment.Text);
|
||||
Profile.Out.Writer.Write(segment.Text);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user