Files
Terminal.Gui/Terminal.Gui/Drivers/V2/WindowSizeMonitor.cs
BDisp ad1de255b1 Fixes #4139. Application.Run<T> isn't initializing properly by setting the Application.ForceDriver property (#4142)
* Fixes #4139. Application.Run<T> isn't initializing properly by setting the Application.ForceDriver property

* Trying fix unit tests

* Only to force again CI tests because I haven't errors locally

* This should pass, unless RunningUnitTests is set to false somewhere

* Fix Unix unit tests and failures via ReSharper

* Changes suggested by @tig

* Prevent empty string

* Centralize all the entry logic in the InternalInit method

* Change GetDriverTypes to return a tuple
2025-06-12 10:48:05 -06:00

43 lines
1.1 KiB
C#

using Microsoft.Extensions.Logging;
namespace Terminal.Gui.Drivers;
internal class WindowSizeMonitor : IWindowSizeMonitor
{
private readonly IConsoleOutput _consoleOut;
private readonly IOutputBuffer _outputBuffer;
private Size _lastSize = new (0, 0);
/// <summary>Invoked when the terminal's size changed. The new size of the terminal is provided.</summary>
public event EventHandler<SizeChangedEventArgs> SizeChanging;
public WindowSizeMonitor (IConsoleOutput consoleOut, IOutputBuffer outputBuffer)
{
_consoleOut = consoleOut;
_outputBuffer = outputBuffer;
}
/// <inheritdoc/>
public bool Poll ()
{
if (ConsoleDriver.RunningUnitTests)
{
return false;
}
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));
return true;
}
return false;
}
}