diff --git a/Terminal.Gui/App/Clipboard/Clipboard.cs b/Terminal.Gui/App/Clipboard/Clipboard.cs
index 6ee6116eb..f8cf39892 100644
--- a/Terminal.Gui/App/Clipboard/Clipboard.cs
+++ b/Terminal.Gui/App/Clipboard/Clipboard.cs
@@ -1,5 +1,4 @@
-using System.Diagnostics;
-
+#nullable enable
namespace Terminal.Gui.App;
/// Provides cut, copy, and paste support for the OS clipboard.
@@ -20,10 +19,10 @@ namespace Terminal.Gui.App;
///
public static class Clipboard
{
- private static string _contents = string.Empty;
+ private static string? _contents = string.Empty;
/// Gets (copies from) or sets (pastes to) the contents of the OS clipboard.
- public static string Contents
+ public static string? Contents
{
get
{
@@ -31,13 +30,8 @@ public static class Clipboard
{
if (IsSupported)
{
- string clipData = Application.Driver?.Clipboard.GetClipboardData ();
-
- if (clipData is null)
- {
- // throw new InvalidOperationException ($"{Application.Driver?.GetType ().Name}.GetClipboardData returned null instead of string.Empty");
- clipData = string.Empty;
- }
+ // throw new InvalidOperationException ($"{Application.Driver?.GetType ().Name}.GetClipboardData returned null instead of string.Empty");
+ string? clipData = Application.Driver?.Clipboard?.GetClipboardData () ?? string.Empty;
_contents = clipData;
}
@@ -55,12 +49,9 @@ public static class Clipboard
{
if (IsSupported)
{
- if (value is null)
- {
- value = string.Empty;
- }
+ value ??= string.Empty;
- Application.Driver?.Clipboard.SetClipboardData (value);
+ Application.Driver?.Clipboard?.SetClipboardData (value);
}
_contents = value;
@@ -74,126 +65,5 @@ public static class Clipboard
/// Returns true if the environmental dependencies are in place to interact with the OS clipboard.
///
- public static bool IsSupported => Application.Driver?.Clipboard.IsSupported ?? false;
-
- /// Copies the _contents of the OS clipboard to if possible.
- /// The _contents of the OS clipboard if successful, if not.
- /// the OS clipboard was retrieved, otherwise.
- public static bool TryGetClipboardData (out string result)
- {
- if (IsSupported && Application.Driver!.Clipboard.TryGetClipboardData (out result))
- {
- _contents = result;
-
- return true;
- }
-
- result = string.Empty;
-
- return false;
- }
-
- /// Pastes the to the OS clipboard if possible.
- /// The text to paste to the OS clipboard.
- /// the OS clipboard was set, otherwise.
- public static bool TrySetClipboardData (string text)
- {
- if (IsSupported && Application.Driver!.Clipboard.TrySetClipboardData (text))
- {
- _contents = text;
-
- return true;
- }
-
- return false;
- }
-}
-
-///
-/// Helper class for console drivers to invoke shell commands to interact with the clipboard. Used primarily by
-/// CursesDriver, but also used in Unit tests which is why it is in IConsoleDriver.cs.
-///
-internal static class ClipboardProcessRunner
-{
- public static (int exitCode, string result) Bash (
- string commandLine,
- string inputText = "",
- bool waitForOutput = false
- )
- {
- var arguments = $"-c \"{commandLine}\"";
- (int exitCode, string result) = Process ("bash", arguments, inputText, waitForOutput);
-
- return (exitCode, result.TrimEnd ());
- }
-
- public static bool DoubleWaitForExit (this Process process)
- {
- bool result = process.WaitForExit (500);
-
- if (result)
- {
- process.WaitForExit ();
- }
-
- return result;
- }
-
- public static bool FileExists (this string value) { return !string.IsNullOrEmpty (value) && !value.Contains ("not found"); }
-
- public static (int exitCode, string result) Process (
- string cmd,
- string arguments,
- string input = null,
- bool waitForOutput = true
- )
- {
- var output = string.Empty;
-
- using (var process = new Process
- {
- StartInfo = new()
- {
- FileName = cmd,
- Arguments = arguments,
- RedirectStandardOutput = true,
- RedirectStandardError = true,
- RedirectStandardInput = true,
- UseShellExecute = false,
- CreateNoWindow = true
- }
- })
- {
- TaskCompletionSource eventHandled = new ();
- process.Start ();
-
- if (!string.IsNullOrEmpty (input))
- {
- process.StandardInput.Write (input);
- process.StandardInput.Close ();
- }
-
- if (!process.WaitForExit (5000))
- {
- var timeoutError =
- $@"Process timed out. Command line: {process.StartInfo.FileName} {process.StartInfo.Arguments}.";
-
- throw new TimeoutException (timeoutError);
- }
-
- if (waitForOutput && process.StandardOutput.Peek () != -1)
- {
- output = process.StandardOutput.ReadToEnd ();
- }
-
- if (process.ExitCode > 0)
- {
- output = $@"Process failed to run. Command line: {cmd} {arguments}.
- Output: {output}
- Error: {process.StandardError.ReadToEnd ()}";
- }
-
- return (process.ExitCode, output);
- }
- }
-}
+ public static bool IsSupported => Application.Driver?.Clipboard?.IsSupported ?? false;
+}
\ No newline at end of file
diff --git a/Terminal.Gui/App/Clipboard/ClipboardProcessRunner.cs b/Terminal.Gui/App/Clipboard/ClipboardProcessRunner.cs
new file mode 100644
index 000000000..707582694
--- /dev/null
+++ b/Terminal.Gui/App/Clipboard/ClipboardProcessRunner.cs
@@ -0,0 +1,79 @@
+#nullable enable
+using System.Diagnostics;
+
+namespace Terminal.Gui.App;
+
+///
+/// Helper class for console drivers to invoke shell commands to interact with the clipboard. Used primarily by
+/// CursesDriver, but also used in Unit tests which is why it is in IConsoleDriver.cs.
+///
+internal static class ClipboardProcessRunner
+{
+ public static (int exitCode, string result) Bash (
+ string commandLine,
+ string inputText = "",
+ bool waitForOutput = false
+ )
+ {
+ var arguments = $"-c \"{commandLine}\"";
+ (int exitCode, string result) = Process ("bash", arguments, inputText, waitForOutput);
+
+ return (exitCode, result.TrimEnd ());
+ }
+
+ public static bool FileExists (this string value) { return !string.IsNullOrEmpty (value) && !value.Contains ("not found"); }
+
+ public static (int exitCode, string result) Process (
+ string cmd,
+ string arguments,
+ string? input = null,
+ bool waitForOutput = true
+ )
+ {
+ var output = string.Empty;
+
+ using var process = new Process ();
+
+ process.StartInfo = new()
+ {
+ FileName = cmd,
+ Arguments = arguments,
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ RedirectStandardInput = true,
+ UseShellExecute = false,
+ CreateNoWindow = true
+ };
+
+ TaskCompletionSource eventHandled = new ();
+ process.Start ();
+
+ if (!string.IsNullOrEmpty (input))
+ {
+ process.StandardInput.Write (input);
+ process.StandardInput.Close ();
+ }
+
+ if (!process.WaitForExit (5000))
+ {
+ var timeoutError =
+ $@"Process timed out. Command line: {process.StartInfo.FileName} {process.StartInfo.Arguments}.";
+
+ throw new TimeoutException (timeoutError);
+ }
+
+ if (waitForOutput && process.StandardOutput.Peek () != -1)
+ {
+ output = process.StandardOutput.ReadToEnd ();
+ }
+
+ if (process.ExitCode > 0)
+ {
+ output = $@"Process failed to run. Command line: {cmd} {arguments}.
+ Output: {output}
+ Error: {process.StandardError.ReadToEnd ()}";
+ }
+
+ return (process.ExitCode, output);
+ }
+}
diff --git a/Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs
index d10d48f92..c377b2071 100644
--- a/Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs
+++ b/Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs
@@ -1,4 +1,5 @@
-//
+#nullable enable
+//
// FakeDriver.cs: A fake IConsoleDriver for unit tests.
//
@@ -36,7 +37,7 @@ public class FakeDriver : ConsoleDriver
public bool UseFakeClipboard { get; internal set; }
}
- public static Behaviors FakeBehaviors = new ();
+ public static Behaviors FakeBehaviors { get; } = new ();
public override bool SupportsTrueColor => false;
///
@@ -47,8 +48,8 @@ public class FakeDriver : ConsoleDriver
public FakeDriver ()
{
- Cols = FakeConsole.WindowWidth = FakeConsole.BufferWidth = FakeConsole.WIDTH;
- Rows = FakeConsole.WindowHeight = FakeConsole.BufferHeight = FakeConsole.HEIGHT;
+ base.Cols = FakeConsole.WindowWidth = FakeConsole.BufferWidth = FakeConsole.WIDTH;
+ base.Rows = FakeConsole.WindowHeight = FakeConsole.BufferHeight = FakeConsole.HEIGHT;
if (FakeBehaviors.UseFakeClipboard)
{
@@ -87,7 +88,7 @@ public class FakeDriver : ConsoleDriver
FakeConsole.Clear ();
}
- private FakeMainLoop _mainLoopDriver;
+ private FakeMainLoop? _mainLoopDriver;
public override MainLoop Init ()
{
@@ -124,7 +125,7 @@ public class FakeDriver : ConsoleDriver
for (int row = top; row < rows; row++)
{
- if (!_dirtyLines [row])
+ if (!_dirtyLines! [row])
{
continue;
}
@@ -144,7 +145,7 @@ public class FakeDriver : ConsoleDriver
for (; col < cols; col++)
{
- if (!Contents [row, col].IsDirty)
+ if (!Contents! [row, col].IsDirty)
{
if (output.Length > 0)
{
@@ -168,7 +169,7 @@ public class FakeDriver : ConsoleDriver
lastCol = col;
}
- Attribute attr = Contents [row, col].Attribute.Value;
+ Attribute attr = Contents [row, col].Attribute!.Value;
// Performance: Only send the escape sequence if the attribute has changed.
if (attr != redrawAttr)
@@ -209,18 +210,18 @@ public class FakeDriver : ConsoleDriver
//SetCursorVisibility (savedVisibility);
- void WriteToConsole (StringBuilder output, ref int lastCol, int row, ref int outputWidth)
+ void WriteToConsole (StringBuilder outputSb, ref int lastColumn, int row, ref int outputWidth)
{
FakeConsole.CursorTop = row;
- FakeConsole.CursorLeft = lastCol;
+ FakeConsole.CursorLeft = lastColumn;
- foreach (char c in output.ToString ())
+ foreach (char c in outputSb.ToString ())
{
FakeConsole.Write (c);
}
- output.Clear ();
- lastCol += outputWidth;
+ outputSb.Clear ();
+ lastColumn += outputWidth;
outputWidth = 0;
}
@@ -506,7 +507,7 @@ public class FakeDriver : ConsoleDriver
public class FakeClipboard : ClipboardBase
{
- public Exception FakeException;
+ public Exception? FakeException { get; set; }
private readonly bool _isSupportedAlwaysFalse;
private string _contents = string.Empty;
@@ -536,19 +537,14 @@ public class FakeDriver : ConsoleDriver
return _contents;
}
- protected override void SetClipboardDataImpl (string text)
+ protected override void SetClipboardDataImpl (string? text)
{
- if (text is null)
- {
- throw new ArgumentNullException (nameof (text));
- }
-
if (FakeException is { })
{
throw FakeException;
}
- _contents = text;
+ _contents = text ?? throw new ArgumentNullException (nameof (text));
}
}
diff --git a/Terminal.Gui/Drivers/V2/ConsoleDriverFacade.cs b/Terminal.Gui/Drivers/V2/ConsoleDriverFacade.cs
index bef8893a0..91879111f 100644
--- a/Terminal.Gui/Drivers/V2/ConsoleDriverFacade.cs
+++ b/Terminal.Gui/Drivers/V2/ConsoleDriverFacade.cs
@@ -1,5 +1,5 @@
-using System.Runtime.InteropServices;
-using Microsoft.Extensions.Logging;
+#nullable enable
+using System.Runtime.InteropServices;
namespace Terminal.Gui.Drivers;
@@ -11,7 +11,7 @@ internal class ConsoleDriverFacade : IConsoleDriver, IConsoleDriverFacade
private CursorVisibility _lastCursor = CursorVisibility.Default;
/// The event fired when the terminal is resized.
- public event EventHandler SizeChanged;
+ public event EventHandler? SizeChanged;
public IInputProcessor InputProcessor { get; }
public IOutputBuffer OutputBuffer => _outputBuffer;
@@ -48,6 +48,13 @@ internal class ConsoleDriverFacade : IConsoleDriver, IConsoleDriverFacade
private void CreateClipboard ()
{
+ if (FakeDriver.FakeBehaviors.UseFakeClipboard)
+ {
+ Clipboard = new FakeDriver.FakeClipboard ();
+
+ return;
+ }
+
PlatformID p = Environment.OSVersion.Platform;
if (p == PlatformID.Win32NT || p == PlatformID.Win32S || p == PlatformID.Win32Windows)
@@ -88,7 +95,7 @@ internal class ConsoleDriverFacade : IConsoleDriver, IConsoleDriverFacade
/// to.
///
/// The rectangle describing the of region.
- public Region Clip
+ public Region? Clip
{
get => _outputBuffer.Clip;
set => _outputBuffer.Clip = value;
@@ -114,7 +121,7 @@ internal class ConsoleDriverFacade : IConsoleDriver, IConsoleDriverFacade
/// The contents of the application output. The driver outputs this buffer to the terminal.
/// The format of the array is rows, columns. The first index is the row, the second index is the column.
///
- public Cell [,] Contents
+ public Cell [,]? Contents
{
get => _outputBuffer.Contents;
set => _outputBuffer.Contents = value;
@@ -229,7 +236,7 @@ internal class ConsoleDriverFacade : IConsoleDriver, IConsoleDriverFacade
///
/// Raised each time is called. For benchmarking.
///
- public event EventHandler ClearedContents;
+ public event EventHandler? ClearedContents;
///
/// Fills the specified rectangle with the specified rune, using
@@ -397,7 +404,7 @@ internal class ConsoleDriverFacade : IConsoleDriver, IConsoleDriverFacade
}
/// Event fired when a key is pressed down. This is a precursor to .
- public event EventHandler KeyDown;
+ public event EventHandler? KeyDown;
/// Event fired when a key is released.
///
@@ -405,10 +412,10 @@ internal class ConsoleDriverFacade : IConsoleDriver, IConsoleDriverFacade
/// processing is
/// complete.
///
- public event EventHandler KeyUp;
+ public event EventHandler? KeyUp;
/// Event fired when a mouse event occurs.
- public event EventHandler MouseEvent;
+ public event EventHandler? MouseEvent;
/// Simulates a key press.
/// The key character.
diff --git a/Terminal.Gui/Drivers/V2/IConsoleDriverFacade.cs b/Terminal.Gui/Drivers/V2/IConsoleDriverFacade.cs
index b670a196d..2d854e16b 100644
--- a/Terminal.Gui/Drivers/V2/IConsoleDriverFacade.cs
+++ b/Terminal.Gui/Drivers/V2/IConsoleDriverFacade.cs
@@ -1,4 +1,5 @@
-namespace Terminal.Gui.Drivers;
+#nullable enable
+namespace Terminal.Gui.Drivers;
///
/// Interface for v2 driver abstraction layer
diff --git a/Terminal.Gui/Drivers/V2/IOutputBuffer.cs b/Terminal.Gui/Drivers/V2/IOutputBuffer.cs
index 6f51ab1ad..4ca6be377 100644
--- a/Terminal.Gui/Drivers/V2/IOutputBuffer.cs
+++ b/Terminal.Gui/Drivers/V2/IOutputBuffer.cs
@@ -12,7 +12,7 @@ public interface IOutputBuffer
///
/// The contents of the application output. The driver outputs this buffer to the terminal when UpdateScreen is called.
///
- Cell [,] Contents { get; set; }
+ Cell [,]? Contents { get; set; }
///
/// Gets or sets the clip rectangle that and are subject
diff --git a/Tests/TerminalGuiFluentTesting/FakeDriver/FakeApplicationFactory.cs b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeApplicationFactory.cs
new file mode 100644
index 000000000..32108b953
--- /dev/null
+++ b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeApplicationFactory.cs
@@ -0,0 +1,45 @@
+#nullable enable
+using System.Drawing;
+using TerminalGuiFluentTesting;
+
+namespace Terminal.Gui.Drivers;
+
+#pragma warning disable CS1591
+public class FakeApplicationFactory
+{
+ ///
+ /// Creates an initialized fake application which will be cleaned up when result object
+ /// is disposed.
+ ///
+ ///
+ public IDisposable SetupFakeApplication ()
+ {
+ var cts = new CancellationTokenSource ();
+ var fakeInput = new FakeNetInput (cts.Token);
+ FakeOutput output = new ();
+ output.Size = new (25, 25);
+
+ IApplication origApp = ApplicationImpl.Instance;
+
+ var sizeMonitor = new FakeSizeMonitor ();
+
+ var v2 = new ApplicationV2 (new FakeNetComponentFactory (fakeInput, output, sizeMonitor));
+
+ ApplicationImpl.ChangeInstance (v2);
+ v2.Init (null, "v2net");
+
+ ConsoleDriverFacade d = (ConsoleDriverFacade)Application.Driver!;
+
+ sizeMonitor.SizeChanging += (_, e) =>
+ {
+ if (e.Size != null)
+ {
+ Size s = e.Size.Value;
+ output.Size = s;
+ d.OutputBuffer.SetWindowSize (s.Width, s.Height);
+ }
+ };
+
+ return new FakeApplicationLifecycle (origApp, cts);
+ }
+}
diff --git a/Tests/TerminalGuiFluentTesting/FakeDriver/FakeApplicationLifecycle.cs b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeApplicationLifecycle.cs
new file mode 100644
index 000000000..7f5da7d7e
--- /dev/null
+++ b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeApplicationLifecycle.cs
@@ -0,0 +1,16 @@
+#nullable enable
+namespace Terminal.Gui.Drivers;
+
+#pragma warning disable CS1591
+internal class FakeApplicationLifecycle (IApplication origApp, CancellationTokenSource hardStop) : IDisposable
+{
+ ///
+ public void Dispose ()
+ {
+ hardStop.Cancel ();
+
+ Application.Top?.Dispose ();
+ Application.Shutdown ();
+ ApplicationImpl.ChangeInstance (origApp);
+ }
+}
diff --git a/Tests/TerminalGuiFluentTesting/FakeDriver/FakeDriverFactory.cs b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeDriverFactory.cs
new file mode 100644
index 000000000..794e050b4
--- /dev/null
+++ b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeDriverFactory.cs
@@ -0,0 +1,20 @@
+#nullable enable
+namespace Terminal.Gui.Drivers;
+
+#pragma warning disable CS1591
+public class FakeDriverFactory
+{
+ ///
+ /// Creates a new instance of using default options
+ ///
+ ///
+ public IFakeDriverV2 Create ()
+ {
+ return new FakeDriverV2 (
+ new (),
+ new (),
+ new (),
+ () => DateTime.Now,
+ new ());
+ }
+}
diff --git a/Tests/TerminalGuiFluentTesting/FakeDriver/FakeDriverV2.cs b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeDriverV2.cs
new file mode 100644
index 000000000..c08b88bd5
--- /dev/null
+++ b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeDriverV2.cs
@@ -0,0 +1,58 @@
+#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;
+
+///
+/// Implementation of that uses fake input/output.
+/// This is a lightweight alternative to (if you don't
+/// need the entire application main loop running).
+///
+internal class FakeDriverV2 : ConsoleDriverFacade, IFakeDriverV2
+{
+ internal FakeDriverV2 (
+ ConcurrentQueue inputBuffer,
+ OutputBuffer outputBuffer,
+ FakeOutput fakeOutput,
+ Func 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);
+ }
+
+ public IConsoleOutput ConsoleOutput { get; }
+ public ConcurrentQueue InputBuffer { get; }
+ public new OutputBuffer OutputBuffer { get; }
+ public FakeSizeMonitor SizeMonitor { get; }
+}
\ No newline at end of file
diff --git a/Tests/TerminalGuiFluentTesting/FakeNetInput.cs b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeNetInput.cs
similarity index 100%
rename from Tests/TerminalGuiFluentTesting/FakeNetInput.cs
rename to Tests/TerminalGuiFluentTesting/FakeDriver/FakeNetInput.cs
diff --git a/Tests/TerminalGuiFluentTesting/FakeDriver/FakeSizeMonitor.cs b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeSizeMonitor.cs
new file mode 100644
index 000000000..2c4a982e9
--- /dev/null
+++ b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeSizeMonitor.cs
@@ -0,0 +1,20 @@
+#nullable enable
+using System.Drawing;
+
+namespace Terminal.Gui.Drivers;
+
+#pragma warning disable CS1591
+public class FakeSizeMonitor : IWindowSizeMonitor
+{
+ ///
+ public event EventHandler? SizeChanging;
+
+ ///
+ public bool Poll () { return false; }
+
+ ///
+ /// Raises the event.
+ ///
+ ///
+ public void RaiseSizeChanging (Size newSize) { SizeChanging?.Invoke (this, new (newSize)); }
+}
diff --git a/Tests/TerminalGuiFluentTesting/FakeDriver/IFakeDriverV2.cs b/Tests/TerminalGuiFluentTesting/FakeDriver/IFakeDriverV2.cs
new file mode 100644
index 000000000..b11384b07
--- /dev/null
+++ b/Tests/TerminalGuiFluentTesting/FakeDriver/IFakeDriverV2.cs
@@ -0,0 +1,8 @@
+#nullable enable
+namespace Terminal.Gui.Drivers;
+
+#pragma warning disable CS1591
+public interface IFakeDriverV2 : IConsoleDriver, IConsoleDriverFacade
+{
+ void SetBufferSize (int width, int height);
+}
diff --git a/Tests/TerminalGuiFluentTesting/FakeDriverV2.cs b/Tests/TerminalGuiFluentTesting/FakeDriverV2.cs
deleted file mode 100644
index 2cf55d85e..000000000
--- a/Tests/TerminalGuiFluentTesting/FakeDriverV2.cs
+++ /dev/null
@@ -1,159 +0,0 @@
-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;
-
-public class FakeApplicationFactory
-{
- ///
- /// Creates an initialized fake application which will be cleaned up when result object
- /// is disposed.
- ///
- ///
- public IDisposable SetupFakeApplication ()
- {
- var cts = new CancellationTokenSource ();
- var fakeInput = new FakeNetInput (cts.Token);
- FakeOutput output = new ();
- output.Size = new (25, 25);
-
-
- IApplication origApp = ApplicationImpl.Instance;
-
- var sizeMonitor = new FakeSizeMonitor ();
-
- var v2 = new ApplicationV2 (new FakeNetComponentFactory (fakeInput, output, sizeMonitor));
-
- ApplicationImpl.ChangeInstance (v2);
- v2.Init (null,"v2net");
-
- var d = (ConsoleDriverFacade)Application.Driver!;
- sizeMonitor.SizeChanging += (_, e) =>
- {
- if (e.Size != null)
- {
- var s = e.Size.Value;
- output.Size = s;
- d.OutputBuffer.SetWindowSize (s.Width, s.Height);
- }
- };
-
- return new FakeApplicationLifecycle (origApp,cts);
- }
-}
-
-class FakeApplicationLifecycle : IDisposable
-{
- private readonly IApplication _origApp;
- private readonly CancellationTokenSource _hardStop;
-
- public FakeApplicationLifecycle (IApplication origApp, CancellationTokenSource hardStop)
- {
- _origApp = origApp;
- _hardStop = hardStop;
- }
- ///
- public void Dispose ()
- {
- _hardStop.Cancel();
-
- Application.Top?.Dispose ();
- Application.Shutdown ();
- ApplicationImpl.ChangeInstance (_origApp);
- }
-}
-
-public class FakeDriverFactory
-{
- ///
- /// Creates a new instance of using default options
- ///
- ///
- public IFakeDriverV2 Create ()
- {
- return new FakeDriverV2 (
- new ConcurrentQueue (),
- new OutputBuffer (),
- new FakeOutput (),
- () => DateTime.Now,
- new FakeSizeMonitor ());
- }
-}
-
-public interface IFakeDriverV2 : IConsoleDriver, IConsoleDriverFacade
-{
- void SetBufferSize (int width, int height);
-}
-
-///
-/// Implementation of that uses fake input/output.
-/// This is a lightweight alternative to (if you don't
-/// need the entire application main loop running).
-///
-class FakeDriverV2 : ConsoleDriverFacade, IFakeDriverV2
-{
- public ConcurrentQueue InputBuffer { get; }
- public FakeSizeMonitor SizeMonitor { get; }
- public new OutputBuffer OutputBuffer { get; }
-
- public IConsoleOutput ConsoleOutput { get; }
-
- private FakeOutput _fakeOutput;
-
- internal FakeDriverV2 (
- ConcurrentQueue inputBuffer,
- OutputBuffer outputBuffer,
- FakeOutput fakeOutput,
- Func datetimeFunc,
- FakeSizeMonitor sizeMonitor) :
- base (new NetInputProcessor (inputBuffer),
- outputBuffer,
- fakeOutput,
- new (new AnsiResponseParser (), datetimeFunc),
- sizeMonitor)
- {
- InputBuffer = inputBuffer;
- SizeMonitor = sizeMonitor;
- OutputBuffer = outputBuffer;
- ConsoleOutput = _fakeOutput = fakeOutput;
- SizeChanged += (_, e) =>
- {
- if (e.Size != null)
- {
- var s = e.Size.Value;
- _fakeOutput.Size = s;
- OutputBuffer.SetWindowSize (s.Width,s.Height);
- }
- };
-
- }
-
- public void SetBufferSize (int width, int height)
- {
- SizeMonitor.RaiseSizeChanging (new Size (width,height));
- OutputBuffer.SetWindowSize (width,height);
- }
-}
-
-public class FakeSizeMonitor : IWindowSizeMonitor
-{
- ///
- public event EventHandler? SizeChanging;
-
- ///
- public bool Poll ()
- {
- return false;
- }
-
- ///
- /// Raises the event.
- ///
- ///
- public void RaiseSizeChanging (Size newSize)
- {
- SizeChanging?.Invoke (this,new (newSize));
- }
-}
diff --git a/Tests/TerminalGuiFluentTesting/FakeOutput.cs b/Tests/TerminalGuiFluentTesting/FakeOutput.cs
index 1b73d9ba1..9f747e8f7 100644
--- a/Tests/TerminalGuiFluentTesting/FakeOutput.cs
+++ b/Tests/TerminalGuiFluentTesting/FakeOutput.cs
@@ -4,7 +4,7 @@ namespace TerminalGuiFluentTesting;
internal class FakeOutput : IConsoleOutput
{
- public IOutputBuffer LastBuffer { get; set; }
+ public IOutputBuffer? LastBuffer { get; set; }
public Size Size { get; set; }
///