#nullable enable
using System.Collections.Concurrent;
namespace Terminal.Gui.Drivers;
///
/// implementation for fake/mock console I/O used in unit tests.
/// This factory creates instances that simulate console behavior without requiring a real terminal.
///
public class FakeComponentFactory : ComponentFactory
{
private readonly ConcurrentQueue? _predefinedInput;
private readonly FakeConsoleOutput? _output;
///
/// Creates a new FakeComponentFactory with optional predefined input and output capture.
///
/// Optional queue of predefined input events to simulate.
/// Optional fake output to capture what would be written to console.
public FakeComponentFactory (ConcurrentQueue? predefinedInput = null, FakeConsoleOutput? output = null)
{
_predefinedInput = predefinedInput;
_output = output;
}
///
public override IConsoleInput CreateInput ()
{
return new FakeConsoleInput (_predefinedInput);
}
///
public override IConsoleOutput CreateOutput ()
{
return _output ?? new FakeConsoleOutput ();
}
///
public override IInputProcessor CreateInputProcessor (ConcurrentQueue inputBuffer)
{
return new NetInputProcessor (inputBuffer);
}
///
public override IConsoleSizeMonitor CreateConsoleSizeMonitor (IConsoleOutput consoleOutput, IOutputBuffer outputBuffer)
{
outputBuffer.SetSize(consoleOutput.GetSize().Width, consoleOutput.GetSize().Height);
return new ConsoleSizeMonitor (consoleOutput, outputBuffer);
}
}