using System;
using Spectre.Console.Rendering;
namespace Spectre.Console
{
///
/// A console capable of writing ANSI escape sequences.
///
public static partial class AnsiConsole
{
///
/// Starts recording the console output.
///
public static void Record()
{
if (_recorder == null)
{
_recorder = new Recorder(Console);
}
}
///
/// Exports all recorded console output as text.
///
/// The recorded output as text.
public static string ExportText()
{
if (_recorder == null)
{
throw new InvalidOperationException("Cannot export text since a recording hasn't been started.");
}
return _recorder.ExportText();
}
///
/// Exports all recorded console output as HTML.
///
/// The recorded output as HTML.
public static string ExportHtml()
{
if (_recorder == null)
{
throw new InvalidOperationException("Cannot export HTML since a recording hasn't been started.");
}
return _recorder.ExportHtml();
}
///
/// Exports all recorded console output using a custom encoder.
///
/// The encoder to use.
/// The recorded output.
public static string ExportCustom(IAnsiConsoleEncoder encoder)
{
if (_recorder == null)
{
throw new InvalidOperationException("Cannot export HTML since a recording hasn't been started.");
}
if (encoder is null)
{
throw new ArgumentNullException(nameof(encoder));
}
return _recorder.Export(encoder);
}
}
}