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 _outputStringBuilder = new (); private int _cursorLeft; private int _cursorTop; private Size _consoleSize = new (80, 25); private IOutputBuffer? _lastBuffer; /// /// /// public FakeOutput () { _lastBuffer = new OutputBufferImpl (); _lastBuffer.SetSize (80, 25); } /// /// Gets or sets the last output buffer written. The contains /// a reference to the buffer last written with . /// public IOutputBuffer? GetLastBuffer () => _lastBuffer; ///// //public override string GetLastOutput () => _outputStringBuilder.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) { // _outputStringBuilder.Append (text); } /// public override void Write (IOutputBuffer buffer) { _lastBuffer = buffer; base.Write (buffer); } ///// //protected override void Write (StringBuilder output) //{ // _outputStringBuilder.Append (output); //} /// public override void SetCursorVisibility (CursorVisibility visibility) { // Capture but don't act on it in fake output } /// protected override void AppendOrWriteAttribute (StringBuilder output, Attribute attr, TextStyle redrawTextStyle) { if (Force16Colors) { if (!IsLegacyConsole) { output.Append (EscSeqUtils.CSI_SetForegroundColor (attr.Foreground.GetAnsiColorCode ())); output.Append (EscSeqUtils.CSI_SetBackgroundColor (attr.Background.GetAnsiColorCode ())); EscSeqUtils.CSI_AppendTextStyleChange (output, redrawTextStyle, attr.Style); } else { Write (output); Console.ForegroundColor = (ConsoleColor)attr.Foreground.GetClosestNamedColor16 (); Console.BackgroundColor = (ConsoleColor)attr.Background.GetClosestNamedColor16 (); } } else { EscSeqUtils.CSI_AppendForegroundColorRGB ( output, attr.Foreground.R, attr.Foreground.G, attr.Foreground.B ); EscSeqUtils.CSI_AppendBackgroundColorRGB ( output, attr.Background.R, attr.Background.G, attr.Background.B ); EscSeqUtils.CSI_AppendTextStyleChange (output, redrawTextStyle, attr.Style); } } /// public void Dispose () { // Nothing to dispose } }