Console Resize Listener
We're listening for any size changes!
Terminaux also provides you with either a polling-based console resize listener for non-Unix systems or a SIGWINCH-based listener for Unix systems that allows your console application, especially the interactive ones, to listen to every single console resize event for all the platforms. It works on Windows, macOS, Linux, and Android.
If you want to use the resize listener functionality, make sure that your application uses .NET Framework 4.8 or .NET 8.0 or higher and install the Terminaux.ResizeListener
package due to the changes to the resize listener functionality.
If you can't upgrade your application, stay on 2.3.0 as it provides polling-based listener that works on Linux.
Functions
The console resize listener contains several of the convenience functions that allow you to control the listener.
WasResized()
: This function tells you if the console has been resized before or not. If it has been resized before, it returnstrue
and sets the cached resized state tofalse
.GetCurrentConsoleSize()
: This function gives you a tuple that represents the cached window width and the window height.
Custom handlers
The console resize listener contains a facility that allows you to set a custom resize handler to change the way how your console application responds to console resizes. This allows you to specify your custom action that gets invoked if the console is resized.
When you start the console resize listener, you'll have an opportunity to specify a custom handler. This way, Terminaux calls your handler if it detects that the console has been resized.
Your custom handler usually does necessary operations to adapt your application to the resized console size. It gets called every time the resize listener detects that your console has been resized.
You can also enable or disable the essential handler to be able to control if Terminaux is allowed to run the essential handler that contains the screen refresh code or not. This is useful for situations where you might not want to refresh the screen unless a specific condition is met. RunEssentialHandler
provides you with this kind of control.