mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00
Add method to write VT/ANSI control codes
Adds a new extension method IAnsiConsole.WriteAnsi that writes VT/ANSI control codes to the console. If VT/ANSI control codes are not supported, nothing will be written.
This commit is contained in:

committed by
Phil Scott

parent
91f910326c
commit
3463dde543
@ -3,11 +3,11 @@ using Spectre.Console.Rendering;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
internal sealed class ControlSequence : Renderable
|
||||
internal sealed class ControlCode : Renderable
|
||||
{
|
||||
private readonly Segment _segment;
|
||||
|
||||
public ControlSequence(string control)
|
||||
public ControlCode(string control)
|
||||
{
|
||||
_segment = Segment.Control(control);
|
||||
}
|
||||
@ -19,7 +19,10 @@ namespace Spectre.Console
|
||||
|
||||
protected override IEnumerable<Segment> Render(RenderContext context, int maxWidth)
|
||||
{
|
||||
yield return _segment;
|
||||
if (context.Ansi)
|
||||
{
|
||||
yield return _segment;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -73,7 +73,7 @@ namespace Spectre.Console
|
||||
public void Refresh()
|
||||
{
|
||||
_renderer.Update(this);
|
||||
_console.Write(new ControlSequence(string.Empty));
|
||||
_console.Write(new ControlCode(string.Empty));
|
||||
}
|
||||
|
||||
internal IReadOnlyList<ProgressTask> GetTasks()
|
||||
|
@ -38,7 +38,7 @@ namespace Spectre.Console
|
||||
|
||||
public void Redraw()
|
||||
{
|
||||
_console.Write(new ControlSequence(string.Empty));
|
||||
_console.Write(new ControlCode(string.Empty));
|
||||
}
|
||||
|
||||
public bool Update(ConsoleKey key)
|
||||
|
Reference in New Issue
Block a user