| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- 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;
- }
- }
|