#nullable enable
using System;
using System.Text;
namespace Terminal.Gui.Drivers;
///
/// Fake console output for testing that captures what would be written to the console.
///
public class FakeConsoleOutput : OutputBase, IConsoleOutput
{
private readonly StringBuilder _output = new ();
private int _cursorLeft;
private int _cursorTop;
private Size _windowSize = new (80, 25);
///
/// Gets the captured output as a string.
///
public string Output => _output.ToString ();
///
/// Clears the captured output.
///
public void ClearOutput () => _output.Clear ();
///
public void SetCursorPosition (int col, int row)
{
SetCursorPositionImpl (col, row);
}
///
protected override bool SetCursorPositionImpl (int col, int row)
{
_cursorLeft = col;
_cursorTop = row;
return true;
}
///
/// Sets the fake window size.
///
public void SetWindowSize (int width, int height)
{
_windowSize = new Size (width, height);
}
///
/// Gets the current cursor position.
///
public (int left, int top) GetCursorPosition () => (_cursorLeft, _cursorTop);
///
public Size GetWindowSize () => _windowSize;
///
public void Write (ReadOnlySpan text)
{
_output.Append (text);
}
///
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);
}
}