ConsoleSizeMonitor.cs 907 B

1234567891011121314151617181920212223242526272829303132333435
  1. #nullable enable
  2. using Microsoft.Extensions.Logging;
  3. namespace Terminal.Gui.Drivers;
  4. /// <inheritdoc />
  5. internal class ConsoleSizeMonitor (IConsoleOutput consoleOut, IOutputBuffer _) : IConsoleSizeMonitor
  6. {
  7. private Size _lastSize = Size.Empty;
  8. /// <summary>Invoked when the terminal's size changed. The new size of the terminal is provided.</summary>
  9. public event EventHandler<SizeChangedEventArgs>? SizeChanged;
  10. /// <inheritdoc/>
  11. public bool Poll ()
  12. {
  13. if (ConsoleDriver.RunningUnitTests)
  14. {
  15. return false;
  16. }
  17. Size size = consoleOut.GetSize ();
  18. if (size != _lastSize)
  19. {
  20. Logging.Logger.LogInformation ($"Console size changes from '{_lastSize}' to {size}");
  21. _lastSize = size;
  22. SizeChanged?.Invoke (this, new (size));
  23. return true;
  24. }
  25. return false;
  26. }
  27. }