SizeMonitorImpl.cs 743 B

1234567891011121314151617181920212223242526272829
  1. using Microsoft.Extensions.Logging;
  2. namespace Terminal.Gui.Drivers;
  3. /// <inheritdoc />
  4. internal class SizeMonitorImpl (IOutput consoleOut) : ISizeMonitor
  5. {
  6. private Size _lastSize = Size.Empty;
  7. /// <summary>Invoked when the terminal's size changed. The new size of the terminal is provided.</summary>
  8. public event EventHandler<SizeChangedEventArgs>? SizeChanged;
  9. /// <inheritdoc/>
  10. public bool Poll ()
  11. {
  12. Size size = consoleOut.GetSize ();
  13. if (size != _lastSize)
  14. {
  15. //Logging.Trace ($"Size changed from '{_lastSize}' to {size}");
  16. _lastSize = size;
  17. SizeChanged?.Invoke (this, new (size));
  18. return true;
  19. }
  20. return false;
  21. }
  22. }