Console Resize Listener

We're listening for any size changes!

Terminaux provides a fast and stable console resize listener 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.

You can start and stop the resize listener using the following functions:

  • StartResizeListener(): Starts the resize listener with either the default resize handler or a custom resize handler that we'll explain later in this page.

  • StopResizeListener(): Stops the resize listener if it's running.

Other 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 returns true and sets the cached resized state to false.

  • 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.

public static void StartResizeListener(Action customHandler = null)

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.