Patrik Svensson cd0d182f12 Add support for recording console output
This commit adds support for recording console output
as well as exporting it to either text or HTML. A user can
also provide their own encoder if they wish.
2020-09-21 13:33:28 +02:00

64 lines
1.8 KiB
C#

using System;
using Spectre.Console.Internal;
namespace Spectre.Console
{
/// <summary>
/// A console capable of writing ANSI escape sequences.
/// </summary>
public static partial class AnsiConsole
{
private static readonly Lazy<IAnsiConsole> _console = new Lazy<IAnsiConsole>(() =>
{
var console = Create(new AnsiConsoleSettings
{
Ansi = AnsiSupport.Detect,
ColorSystem = ColorSystemSupport.Detect,
Out = System.Console.Out,
});
Initialize(System.Console.Out);
Created = true;
return console;
});
private static Recorder? _recorder;
/// <summary>
/// Gets the underlying <see cref="IAnsiConsole"/>.
/// </summary>
public static IAnsiConsole Console => _recorder ?? _console.Value;
/// <summary>
/// Gets the console's capabilities.
/// </summary>
public static Capabilities Capabilities => Console.Capabilities;
/// <summary>
/// Gets the buffer width of the console.
/// </summary>
public static int Width
{
get => Console.Width;
}
/// <summary>
/// Gets the buffer height of the console.
/// </summary>
public static int Height
{
get => Console.Height;
}
/// <summary>
/// Creates a new <see cref="IAnsiConsole"/> instance
/// from the provided settings.
/// </summary>
/// <param name="settings">The settings to use.</param>
/// <returns>An <see cref="IAnsiConsole"/> instance.</returns>
public static IAnsiConsole Create(AnsiConsoleSettings settings)
{
return AnsiConsoleBuilder.Build(settings);
}
}
}