diff --git a/Terminal.Gui/Drivers/V2/IConsoleOutput.cs b/Terminal.Gui/Drivers/V2/IConsoleOutput.cs
index aa6280adf..d591098e9 100644
--- a/Terminal.Gui/Drivers/V2/IConsoleOutput.cs
+++ b/Terminal.Gui/Drivers/V2/IConsoleOutput.cs
@@ -23,9 +23,15 @@ public interface IConsoleOutput : IDisposable
/// Returns the current size of the console window in rows/columns (i.e.
/// of characters not pixels).
///
- ///
///
- public Size GetWindowSize (Size? lastSize = null);
+ public Size GetWindowSize ();
+
+ ///
+ /// Sets the current size of the console window in rows/columns
+ ///
+ ///
+ /// ///
+ public Size SetWindowSize (Size newSize);
///
/// Updates the console cursor (the blinking underscore) to be hidden,
diff --git a/Terminal.Gui/Drivers/V2/NetOutput.cs b/Terminal.Gui/Drivers/V2/NetOutput.cs
index 68d357dd4..e0b62ba72 100644
--- a/Terminal.Gui/Drivers/V2/NetOutput.cs
+++ b/Terminal.Gui/Drivers/V2/NetOutput.cs
@@ -202,7 +202,7 @@ public class NetOutput : IConsoleOutput
}
///
- public Size GetWindowSize (Size? lastSize = null)
+ public Size GetWindowSize ()
{
if (ConsoleDriver.RunningUnitTests)
{
@@ -213,6 +213,12 @@ public class NetOutput : IConsoleOutput
return new (Console.WindowWidth, Console.WindowHeight);
}
+ ///
+ public Size SetWindowSize (Size newSize)
+ {
+ return newSize;
+ }
+
private void WriteToConsole (StringBuilder output, ref int lastCol, int row, ref int outputWidth)
{
SetCursorPositionImpl (lastCol, row);
diff --git a/Terminal.Gui/Drivers/V2/WindowSizeMonitor.cs b/Terminal.Gui/Drivers/V2/WindowSizeMonitor.cs
index 6d8dbe3a1..f29b9db58 100644
--- a/Terminal.Gui/Drivers/V2/WindowSizeMonitor.cs
+++ b/Terminal.Gui/Drivers/V2/WindowSizeMonitor.cs
@@ -25,14 +25,21 @@ internal class WindowSizeMonitor : IWindowSizeMonitor
return false;
}
- Size size = _consoleOut.GetWindowSize (_lastSize);
+ Size size = _consoleOut.GetWindowSize ();
if (size != _lastSize)
{
Logging.Logger.LogInformation ($"Console size changes from '{_lastSize}' to {size}");
- _outputBuffer.SetWindowSize (size.Width, size.Height);
- _lastSize = size;
- SizeChanging?.Invoke (this, new (size));
+ Size newSize = size;
+
+ if (_consoleOut.GetType().Name == "WindowsOutput")
+ {
+ newSize = _consoleOut.SetWindowSize (size);
+ }
+
+ _outputBuffer.SetWindowSize (newSize.Width, newSize.Height);
+ _lastSize = newSize;
+ SizeChanging?.Invoke (this, new (newSize));
return true;
}
diff --git a/Terminal.Gui/Drivers/V2/WindowsOutput.cs b/Terminal.Gui/Drivers/V2/WindowsOutput.cs
index 83df6a672..1275ba608 100644
--- a/Terminal.Gui/Drivers/V2/WindowsOutput.cs
+++ b/Terminal.Gui/Drivers/V2/WindowsOutput.cs
@@ -466,7 +466,7 @@ internal partial class WindowsOutput : IConsoleOutput
return result;
}
- public Size GetWindowSize (Size? lastSize = null)
+ public Size GetWindowSize ()
{
var csbi = new WindowsConsole.CONSOLE_SCREEN_BUFFER_INFOEX ();
csbi.cbSize = (uint)Marshal.SizeOf (csbi);
@@ -481,17 +481,19 @@ internal partial class WindowsOutput : IConsoleOutput
csbi.srWindow.Right - csbi.srWindow.Left + 1,
csbi.srWindow.Bottom - csbi.srWindow.Top + 1);
- if (lastSize is { } && sz != lastSize)
- {
- Size newSize = SetConsoleWindow ((short)sz.Width, (short)sz.Height);
+ return sz;
+ }
- if (sz != newSize)
- {
- return newSize;
- }
+ public Size SetWindowSize (Size newSize)
+ {
+ Size resSize = SetConsoleWindow ((short)newSize.Width, (short)newSize.Height);
+
+ if (resSize != newSize)
+ {
+ return resSize;
}
- return sz;
+ return newSize;
}
private Size SetConsoleWindow (short cols, short rows)
diff --git a/Tests/TerminalGuiFluentTesting/FakeOutput.cs b/Tests/TerminalGuiFluentTesting/FakeOutput.cs
index 6255de358..5b475b025 100644
--- a/Tests/TerminalGuiFluentTesting/FakeOutput.cs
+++ b/Tests/TerminalGuiFluentTesting/FakeOutput.cs
@@ -17,7 +17,10 @@ internal class FakeOutput : IConsoleOutput
public void Write (IOutputBuffer buffer) { LastBuffer = buffer; }
///
- public Size GetWindowSize (Size? lastSize = null) { return Size; }
+ public Size GetWindowSize () { return Size; }
+
+ ///
+ public Size SetWindowSize (Size newSize) { return newSize; }
///
public void SetCursorVisibility (CursorVisibility visibility) { }
diff --git a/Tests/UnitTests/ConsoleDrivers/V2/WindowSizeMonitorTests.cs b/Tests/UnitTests/ConsoleDrivers/V2/WindowSizeMonitorTests.cs
index 5107a511b..89dde8af1 100644
--- a/Tests/UnitTests/ConsoleDrivers/V2/WindowSizeMonitorTests.cs
+++ b/Tests/UnitTests/ConsoleDrivers/V2/WindowSizeMonitorTests.cs
@@ -19,7 +19,7 @@ public class WindowSizeMonitorTests
});
- consoleOutput.Setup (m => m.GetWindowSize (null))
+ consoleOutput.Setup (m => m.GetWindowSize ())
.Returns (queue.Dequeue);
var outputBuffer = Mock.Of ();
@@ -52,7 +52,7 @@ public class WindowSizeMonitorTests
new Size (30, 20),
});
- consoleOutput.Setup (m => m.GetWindowSize (null))
+ consoleOutput.Setup (m => m.GetWindowSize ())
.Returns (queue.Dequeue);
var outputBuffer = Mock.Of ();