2
0

FakeConsoleDriver.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #nullable enable
  2. using System.Collections.Concurrent;
  3. using System.Drawing;
  4. using TerminalGuiFluentTesting;
  5. #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
  6. namespace Terminal.Gui.Drivers;
  7. /// <summary>
  8. /// Implementation of <see cref="IConsoleDriver"/> that uses fake input/output.
  9. /// This is a lightweight alternative to <see cref="GuiTestContext"/> (if you don't
  10. /// need the entire application main loop running).
  11. /// </summary>
  12. internal class FakeConsoleDriver : ConsoleDriverFacade<ConsoleKeyInfo>, IFakeConsoleDriver
  13. {
  14. internal FakeConsoleDriver (
  15. ConcurrentQueue<ConsoleKeyInfo> inputBuffer,
  16. OutputBuffer outputBuffer,
  17. FakeOutput fakeOutput,
  18. Func<DateTime> datetimeFunc,
  19. FakeSizeMonitor sizeMonitor
  20. ) :
  21. base (
  22. new NetInputProcessor (inputBuffer),
  23. outputBuffer,
  24. fakeOutput,
  25. new (new AnsiResponseParser (), datetimeFunc),
  26. sizeMonitor)
  27. {
  28. FakeOutput fakeOutput1;
  29. InputBuffer = inputBuffer;
  30. SizeMonitor = sizeMonitor;
  31. OutputBuffer = outputBuffer;
  32. ConsoleOutput = fakeOutput1 = fakeOutput;
  33. SizeChanged += (_, e) =>
  34. {
  35. if (e.Size != null)
  36. {
  37. Size s = e.Size.Value;
  38. fakeOutput1.Size = s;
  39. OutputBuffer.SetWindowSize (s.Width, s.Height);
  40. }
  41. };
  42. }
  43. public void SetBufferSize (int width, int height)
  44. {
  45. SizeMonitor.RaiseSizeChanging (new (width, height));
  46. OutputBuffer.SetWindowSize (width, height);
  47. }
  48. public IConsoleOutput ConsoleOutput { get; }
  49. public ConcurrentQueue<ConsoleKeyInfo> InputBuffer { get; }
  50. public new OutputBuffer OutputBuffer { get; }
  51. public FakeSizeMonitor SizeMonitor { get; }
  52. }