mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-07-06 04:28:15 +08:00

committed by
Patrik Svensson

parent
913a7b1e37
commit
a23bec4082
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Spectre.Console.Rendering;
|
||||
|
||||
namespace Spectre.Console.Testing
|
||||
@ -13,10 +12,7 @@ namespace Spectre.Console.Testing
|
||||
|
||||
public string Output => _writer.ToString();
|
||||
|
||||
public Capabilities Capabilities => _console.Capabilities;
|
||||
public Encoding Encoding => _console.Encoding;
|
||||
public int Width { get; }
|
||||
public int Height => _console.Height;
|
||||
public Profile Profile => _console.Profile;
|
||||
public IAnsiConsoleCursor Cursor => _console.Cursor;
|
||||
public FakeConsoleInput Input { get; }
|
||||
public RenderPipeline Pipeline => _console.Pipeline;
|
||||
@ -24,21 +20,22 @@ namespace Spectre.Console.Testing
|
||||
IAnsiConsoleInput IAnsiConsole.Input => Input;
|
||||
|
||||
public FakeAnsiConsole(
|
||||
ColorSystem system, AnsiSupport ansi = AnsiSupport.Yes,
|
||||
InteractionSupport interaction = InteractionSupport.Yes,
|
||||
ColorSystem system,
|
||||
AnsiSupport ansi = AnsiSupport.Yes,
|
||||
int width = 80)
|
||||
{
|
||||
_writer = new StringWriter();
|
||||
_console = AnsiConsole.Create(new AnsiConsoleSettings
|
||||
|
||||
var factory = AnsiConsoleFactory.NoEnrichers();
|
||||
_console = factory.Create(new AnsiConsoleSettings
|
||||
{
|
||||
Ansi = ansi,
|
||||
ColorSystem = (ColorSystemSupport)system,
|
||||
Interactive = interaction,
|
||||
Out = _writer,
|
||||
LinkIdentityGenerator = new FakeLinkIdentityGenerator(1024),
|
||||
});
|
||||
|
||||
Width = width;
|
||||
_console.Profile.Width = width;
|
||||
|
||||
Input = new FakeConsoleInput();
|
||||
}
|
||||
|
||||
|
@ -9,14 +9,10 @@ namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class FakeConsole : IAnsiConsole, IDisposable
|
||||
{
|
||||
public Capabilities Capabilities { get; }
|
||||
public Encoding Encoding { get; }
|
||||
public Profile Profile { get; }
|
||||
public IAnsiConsoleCursor Cursor => new FakeAnsiConsoleCursor();
|
||||
public FakeConsoleInput Input { get; }
|
||||
|
||||
public int Width { get; }
|
||||
public int Height { get; }
|
||||
|
||||
IAnsiConsoleInput IAnsiConsole.Input => Input;
|
||||
public RenderPipeline Pipeline { get; }
|
||||
|
||||
@ -34,13 +30,18 @@ namespace Spectre.Console.Testing
|
||||
bool supportsAnsi = true, ColorSystem colorSystem = ColorSystem.Standard,
|
||||
bool legacyConsole = false, bool interactive = true)
|
||||
{
|
||||
Capabilities = new Capabilities(supportsAnsi, colorSystem, legacyConsole, interactive);
|
||||
Encoding = encoding ?? Encoding.UTF8;
|
||||
Width = width;
|
||||
Height = height;
|
||||
Writer = new StringWriter();
|
||||
Input = new FakeConsoleInput();
|
||||
Pipeline = new RenderPipeline();
|
||||
|
||||
Profile = new Profile("Fake console", Writer, encoding ?? Encoding.UTF8);
|
||||
Profile.Width = width;
|
||||
Profile.Height = height;
|
||||
Profile.ColorSystem = colorSystem;
|
||||
Profile.Capabilities.Ansi = supportsAnsi;
|
||||
Profile.Capabilities.Legacy = legacyConsole;
|
||||
Profile.Capabilities.Interactive = interactive;
|
||||
Profile.Capabilities.Links = true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
@ -1,17 +0,0 @@
|
||||
namespace Spectre.Console.Testing
|
||||
{
|
||||
public sealed class FakeLinkIdentityGenerator : ILinkIdentityGenerator
|
||||
{
|
||||
private readonly int _linkId;
|
||||
|
||||
public FakeLinkIdentityGenerator(int linkId)
|
||||
{
|
||||
_linkId = linkId;
|
||||
}
|
||||
|
||||
public int GenerateId(string link, string text)
|
||||
{
|
||||
return _linkId;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user