Skip to content

Latest commit

 

History

History
76 lines (45 loc) · 1.79 KB

File metadata and controls

76 lines (45 loc) · 1.79 KB

📡 Events API

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.


📦 Accessing Events

You can access the Events class in two ways:

const Console = require('softio');
Console.Events;

Or directly via destructuring:

const { Events } = require('softio');

🧠 Available Methods

🔹 static addEventListener(type: EventTypesT, listener: Function): void

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!');
});

🔹 static removeEventListener(type: EventTypesT): void

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');

✅ Summary

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.