SizeMonitorImpl.cs 760 B

123456789101112131415161718192021222324252627282930
  1. #nullable enable
  2. using Microsoft.Extensions.Logging;
  3. namespace Terminal.Gui.Drivers;
  4. /// <inheritdoc />
  5. internal class SizeMonitorImpl (IOutput consoleOut) : ISizeMonitor
  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. Size size = consoleOut.GetSize ();
  14. if (size != _lastSize)
  15. {
  16. //Logging.Trace ($"Size changed from '{_lastSize}' to {size}");
  17. _lastSize = size;
  18. SizeChanged?.Invoke (this, new (size));
  19. return true;
  20. }
  21. return false;
  22. }
  23. }