#nullable enable
using System;
namespace Terminal.Gui.Drivers;
///
/// Fake console output for testing that captures what would be written to the console.
///
public class FakeOutput : OutputBase, IOutput
{
private readonly StringBuilder _output = new ();
private int _cursorLeft;
private int _cursorTop;
private Size _consoleSize = new (80, 25);
///
///
///
public FakeOutput ()
{
LastBuffer = new OutputBufferImpl ();
LastBuffer.SetSize (80, 25);
}
///
/// Gets or sets the last output buffer written.
///
public IOutputBuffer? LastBuffer { get; set; }
///
/// Gets the captured output as a string.
///
public string Output => _output.ToString ();
///
public Point GetCursorPosition ()
{
return new (_cursorLeft, _cursorTop);
}
///
public void SetCursorPosition (int col, int row) { SetCursorPositionImpl (col, row); }
///
public void SetSize (int width, int height)
{
_consoleSize = new (width, height);
}
///
protected override bool SetCursorPositionImpl (int col, int row)
{
_cursorLeft = col;
_cursorTop = row;
return true;
}
///
public Size GetSize () { return _consoleSize; }
///
public void Write (ReadOnlySpan text)
{
_output.Append (text);
}
///
public override void Write (IOutputBuffer buffer)
{
LastBuffer = buffer;
base.Write (buffer);
}
///
public override void SetCursorVisibility (CursorVisibility visibility)
{
// Capture but don't act on it in fake output
}
///
public void Dispose ()
{
// Nothing to dispose
}
///
protected override void AppendOrWriteAttribute (StringBuilder output, Attribute attr, TextStyle redrawTextStyle)
{
// For testing, we can skip the actual color/style output
// or capture it if needed for verification
}
///
protected override void Write (StringBuilder output)
{
_output.Append (output);
}
}