| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #nullable enable
- using System.Collections.Concurrent;
- using System.Drawing;
- using TerminalGuiFluentTesting;
- #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
- namespace Terminal.Gui.Drivers;
- /// <summary>
- /// Implementation of <see cref="IConsoleDriver"/> that uses fake input/output.
- /// This is a lightweight alternative to <see cref="GuiTestContext"/> (if you don't
- /// need the entire application main loop running).
- /// </summary>
- internal class FakeConsoleDriver : ConsoleDriverFacade<ConsoleKeyInfo>, IFakeConsoleDriver
- {
- internal FakeConsoleDriver (
- ConcurrentQueue<ConsoleKeyInfo> inputBuffer,
- OutputBuffer outputBuffer,
- FakeOutput fakeOutput,
- Func<DateTime> datetimeFunc,
- FakeSizeMonitor sizeMonitor
- ) :
- base (
- new NetInputProcessor (inputBuffer),
- outputBuffer,
- fakeOutput,
- new (new AnsiResponseParser (), datetimeFunc),
- sizeMonitor)
- {
- FakeOutput fakeOutput1;
- InputBuffer = inputBuffer;
- SizeMonitor = sizeMonitor;
- OutputBuffer = outputBuffer;
- ConsoleOutput = fakeOutput1 = fakeOutput;
- SizeChanged += (_, e) =>
- {
- if (e.Size != null)
- {
- Size s = e.Size.Value;
- fakeOutput1.Size = s;
- OutputBuffer.SetWindowSize (s.Width, s.Height);
- }
- };
- }
- public void SetBufferSize (int width, int height)
- {
- SizeMonitor.RaiseSizeChanging (new (width, height));
- OutputBuffer.SetWindowSize (width, height);
- }
- /// <summary>
- /// Sets the screen size for testing purposes.
- /// </summary>
- /// <param name="width">The new width (columns).</param>
- /// <param name="height">The new height (rows).</param>
- public override void SetScreenSize (int width, int height)
- {
- SetBufferSize (width, height);
- }
- public IConsoleOutput ConsoleOutput { get; }
- public ConcurrentQueue<ConsoleKeyInfo> InputBuffer { get; }
- public new OutputBuffer OutputBuffer { get; }
- public FakeSizeMonitor SizeMonitor { get; }
- }
|