The Events class in Softio provides methods for handling runtime console events such as window resizing. This enables dynamic behavior in response to changes in the console environment.
You can access the Events class in two ways:
const Console = require('softio');
Console.Events;Or directly via destructuring:
const { Events } = require('softio');Registers a callback function that will be invoked when a specific console event occurs.
-
Parameters:
type— (EventTypesT): The name of the event to listen for.listener— (Function): A function to execute when the event is triggered.
-
Supported Event Types:
'resize'— Fired when the terminal window size changes.
-
Example:
Console.Events.addEventListener('resize', () => {
Console.Out.writeln('Console resized!');
});Unregisters a previously added event listener.
-
Parameters:
type— (EventTypesT): The type of event for which the listener should be removed.
-
Example:
Console.Events.removeEventListener('resize');The Events class provides minimal yet essential support for managing runtime console behaviors. As of now, the only supported event is:
resize— Enables responsive CLI interfaces that react to terminal size changes.
This is especially useful when designing dynamic layouts or rendering adaptive UIs in the terminal.
- Back to the previous section: 🎛️ Attr Methods ←
- Continue to the next section: 🍁 Styler Methods →