diff --git a/Terminal.Gui/Drivers/ConsoleDriver.cs b/Terminal.Gui/Drivers/ConsoleDriver.cs
index 534adefb7..8e71731d2 100644
--- a/Terminal.Gui/Drivers/ConsoleDriver.cs
+++ b/Terminal.Gui/Drivers/ConsoleDriver.cs
@@ -531,6 +531,20 @@ public abstract class ConsoleDriver : IConsoleDriver
/// upon success
public abstract bool SetCursorVisibility (CursorVisibility visibility);
+ ///
+ /// Sets the screen (terminal) size. This method is primarily used for testing with .
+ ///
+ ///
+ /// Only implements this method. Other drivers throw .
+ ///
+ /// The new width (columns).
+ /// The new height (rows).
+ /// Thrown by all drivers except .
+ public virtual void SetScreenSize (int width, int height)
+ {
+ throw new NotImplementedException ("SetScreenSize is only supported by FakeDriver for testing purposes.");
+ }
+
/// The event fired when the terminal is resized.
public event EventHandler? SizeChanged;
diff --git a/Terminal.Gui/Drivers/ConsoleDriverFacade.cs b/Terminal.Gui/Drivers/ConsoleDriverFacade.cs
index ef12ec04e..692d39e85 100644
--- a/Terminal.Gui/Drivers/ConsoleDriverFacade.cs
+++ b/Terminal.Gui/Drivers/ConsoleDriverFacade.cs
@@ -317,6 +317,20 @@ internal class ConsoleDriverFacade : IConsoleDriver, IConsoleDriverFacade
return true;
}
+ ///
+ /// Sets the screen (terminal) size. This method is only supported by FakeDriver.
+ ///
+ ///
+ /// This is a pass-through to the underlying driver. Only FakeDriver implements this; other drivers throw .
+ ///
+ /// The new width (columns).
+ /// The new height (rows).
+ /// Thrown by all drivers except FakeDriver.
+ public virtual void SetScreenSize (int width, int height)
+ {
+ throw new NotImplementedException ("SetScreenSize is only supported by FakeDriver for testing purposes.");
+ }
+
///
public bool GetCursorVisibility (out CursorVisibility current)
{
diff --git a/Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs b/Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs
index 916760c97..46ad76854 100644
--- a/Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs
+++ b/Terminal.Gui/Drivers/FakeDriver/FakeDriver.cs
@@ -401,6 +401,20 @@ public class FakeDriver : ConsoleDriver
ProcessResize ();
}
+ ///
+ /// Sets the screen (terminal) size for testing purposes.
+ ///
+ ///
+ /// This method updates and ,
+ /// resizes the internal buffers, clears contents, and fires the event.
+ ///
+ /// The new width (columns).
+ /// The new height (rows).
+ public override void SetScreenSize (int width, int height)
+ {
+ SetWindowSize (width, height);
+ }
+
public void SetWindowPosition (int left, int top)
{
if (Left > 0 || Top > 0)
diff --git a/Terminal.Gui/Drivers/IConsoleDriver.cs b/Terminal.Gui/Drivers/IConsoleDriver.cs
index a28671a4e..ff5a275a7 100644
--- a/Terminal.Gui/Drivers/IConsoleDriver.cs
+++ b/Terminal.Gui/Drivers/IConsoleDriver.cs
@@ -200,6 +200,22 @@ public interface IConsoleDriver
/// upon success
bool SetCursorVisibility (CursorVisibility visibility);
+ ///
+ /// Sets the screen (terminal) size. This method is primarily used for testing with .
+ ///
+ ///
+ ///
+ /// Only implements this method. Other drivers throw .
+ ///
+ ///
+ /// When implemented, this method updates and , clears the contents buffer,
+ /// and fires the event.
+ ///
+ ///
+ /// The new width (columns).
+ /// The new height (rows).
+ void SetScreenSize (int width, int height);
+
/// The event fired when the terminal is resized.
event EventHandler? SizeChanged;
diff --git a/Tests/TerminalGuiFluentTesting/FakeDriver/FakeConsoleDriver.cs b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeConsoleDriver.cs
index 4b42dee78..f5664c9e1 100644
--- a/Tests/TerminalGuiFluentTesting/FakeDriver/FakeConsoleDriver.cs
+++ b/Tests/TerminalGuiFluentTesting/FakeDriver/FakeConsoleDriver.cs
@@ -51,6 +51,16 @@ internal class FakeConsoleDriver : ConsoleDriverFacade, IFakeCon
OutputBuffer.SetWindowSize (width, height);
}
+ ///
+ /// Sets the screen size for testing purposes.
+ ///
+ /// The new width (columns).
+ /// The new height (rows).
+ public override void SetScreenSize (int width, int height)
+ {
+ SetBufferSize (width, height);
+ }
+
public IConsoleOutput ConsoleOutput { get; }
public ConcurrentQueue InputBuffer { get; }
public new OutputBuffer OutputBuffer { get; }
diff --git a/Tests/UnitTests/AutoInitShutdownAttribute.cs b/Tests/UnitTests/AutoInitShutdownAttribute.cs
index b5e11ccbc..dbc81e7ad 100644
--- a/Tests/UnitTests/AutoInitShutdownAttribute.cs
+++ b/Tests/UnitTests/AutoInitShutdownAttribute.cs
@@ -155,25 +155,50 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute
private bool AutoInit { get; }
///
- /// 'Resizes' the application and forces layout. Only works if your test uses
+ /// 'Resizes' the application screen and forces layout. Only works if your test uses
+ /// with FakeDriver (the default).
///
- ///
+ /// The new screen size.
+ ///
+ /// This method works with both the library FakeDriver and the fluent testing FakeConsoleDriver.
+ /// It uses when available, or manipulates the buffer/monitor directly.
+ ///
public static void FakeResize (Size size)
{
- var d = (IConsoleDriverFacade)Application.Driver!;
- d.OutputBuffer.SetWindowSize (size.Width, size.Height);
-
- // Handle both FakeSizeMonitor (from test project) and FakeWindowSizeMonitor (from main library)
- if (d.WindowSizeMonitor is FakeSizeMonitor fakeSizeMonitor)
+ if (Application.Driver is null)
{
- fakeSizeMonitor.RaiseSizeChanging (size);
- }
- else if (d.WindowSizeMonitor is FakeWindowSizeMonitor fakeWindowSizeMonitor)
- {
- // For FakeWindowSizeMonitor, use the RaiseSizeChanging method
- fakeWindowSizeMonitor.RaiseSizeChanging (size);
+ return;
}
+ // Try the library FakeDriver first - it has SetScreenSize implemented
+ if (Application.Driver is FakeDriver fakeDriver)
+ {
+ fakeDriver.SetScreenSize (size.Width, size.Height);
+ Application.LayoutAndDraw (true);
+ return;
+ }
+
+ // For fluent testing FakeConsoleDriver (through facade), manipulate buffer and monitor directly
+ if (Application.Driver is IConsoleDriverFacade facade)
+ {
+ facade.OutputBuffer.SetWindowSize (size.Width, size.Height);
+
+ // Raise the size changing event through the monitor
+ if (facade.WindowSizeMonitor is FakeSizeMonitor fakeSizeMonitor)
+ {
+ fakeSizeMonitor.RaiseSizeChanging (size);
+ }
+ else if (facade.WindowSizeMonitor is FakeWindowSizeMonitor fakeWindowSizeMonitor)
+ {
+ fakeWindowSizeMonitor.RaiseSizeChanging (size);
+ }
+
+ Application.LayoutAndDraw (true);
+ return;
+ }
+
+ // Fallback: try SetScreenSize through interface (will throw if not supported)
+ Application.Driver.SetScreenSize (size.Width, size.Height);
Application.LayoutAndDraw (true);
}
diff --git a/Tests/UnitTestsParallelizable/MockConsoleDriver.cs b/Tests/UnitTestsParallelizable/MockConsoleDriver.cs
index 50f025834..c427719a0 100644
--- a/Tests/UnitTestsParallelizable/MockConsoleDriver.cs
+++ b/Tests/UnitTestsParallelizable/MockConsoleDriver.cs
@@ -145,6 +145,9 @@ internal class MockConsoleDriver : IConsoleDriver
///
public bool SetCursorVisibility (CursorVisibility visibility) { throw new NotImplementedException (); }
+ ///
+ public void SetScreenSize (int width, int height) { throw new NotImplementedException ("SetScreenSize is only supported by FakeDriver for testing purposes."); }
+
///
public event EventHandler? SizeChanged;