mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2025-10-25 15:19:23 +00:00
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.
55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using Spectre.Console.Rendering;
|
|
|
|
namespace Spectre.Console.Tests
|
|
{
|
|
public sealed class PlainConsole : IAnsiConsole, IDisposable
|
|
{
|
|
public Capabilities Capabilities { get; }
|
|
public Encoding Encoding { get; }
|
|
|
|
public int Width { get; }
|
|
public int Height { get; }
|
|
|
|
public Decoration Decoration { get; set; }
|
|
public Color Foreground { get; set; }
|
|
public Color Background { get; set; }
|
|
public string Link { get; set; }
|
|
|
|
public StringWriter Writer { get; }
|
|
public string RawOutput => Writer.ToString();
|
|
public string Output => Writer.ToString().TrimEnd('\n');
|
|
public IReadOnlyList<string> Lines => Output.Split(new char[] { '\n' });
|
|
|
|
public PlainConsole(
|
|
int width = 80, int height = 9000, Encoding encoding = null,
|
|
bool supportsAnsi = true, ColorSystem colorSystem = ColorSystem.Standard,
|
|
bool legacyConsole = false)
|
|
{
|
|
Capabilities = new Capabilities(supportsAnsi, colorSystem, legacyConsole);
|
|
Encoding = encoding ?? Encoding.UTF8;
|
|
Width = width;
|
|
Height = height;
|
|
Writer = new StringWriter();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Writer.Dispose();
|
|
}
|
|
|
|
public void Write(Segment segment)
|
|
{
|
|
if (segment is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(segment));
|
|
}
|
|
|
|
Writer.Write(segment.Text);
|
|
}
|
|
}
|
|
}
|