mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2026-01-02 01:03:32 +01:00
Also moves tests to `./test` which makes it possible for all test projects to share the same .editorconfig files and similar.
41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
using System;
|
|
using Spectre.Console.Rendering;
|
|
using static Spectre.Console.AnsiSequences;
|
|
|
|
namespace Spectre.Console
|
|
{
|
|
internal sealed class AnsiConsoleBackend : IAnsiConsoleBackend
|
|
{
|
|
private readonly IAnsiConsole _console;
|
|
|
|
public IAnsiConsoleCursor Cursor { get; }
|
|
|
|
public AnsiConsoleBackend(IAnsiConsole console)
|
|
{
|
|
_console = console ?? throw new ArgumentNullException(nameof(console));
|
|
Cursor = new AnsiConsoleCursor(this);
|
|
}
|
|
|
|
public void Clear(bool home)
|
|
{
|
|
Write(new ControlCode(ED(2)));
|
|
Write(new ControlCode(ED(3)));
|
|
|
|
if (home)
|
|
{
|
|
Write(new ControlCode(CUP(1, 1)));
|
|
}
|
|
}
|
|
|
|
public void Write(IRenderable renderable)
|
|
{
|
|
var result = AnsiBuilder.Build(_console, renderable);
|
|
if (result?.Length > 0)
|
|
{
|
|
_console.Profile.Out.Writer.Write(result);
|
|
_console.Profile.Out.Writer.Flush();
|
|
}
|
|
}
|
|
}
|
|
}
|