MenuEvents

The MenuEvents interface defines the event map for a menu component in ts-better-console. It describes the events that can be emitted by a menu, allowing you to respond to user selections and exits.

Type Definition

The MenuEvents interface includes the following events:

  • select: Emitted when the user selects a menu item. Provides the label (string) of the selected item and its index (number) within the menu.
  • exit: Emitted when the user exits the menu. No arguments are passed.
interface MenuEvents {
  select: [label: string, index: number];
  exit: [];
}

Usage

You can listen to MenuEvents when using a menu to handle user interactions:

import { Menu } from "ts-better-console";

const m = new Menu([
{ label: "Option 1" },
{ label: "Option 2" },
{ label: "Option 3" },
]);

m.on("select", (label, index) => {
console.log(`Selected: ${label} at index ${index}`);
m.destroy();
});

m.on("exit", () => {
console.log("Menu closed");
});

m.show();

Want to support this project?

If you find ts-better-console useful and want to support its development, consider starring the GitHub repository or buying me a coffee! Your support helps me dedicate more time to improving the library and adding new features.

Want to contribute to this project?

Contributions are welcome! If you're interested in improving the library, fixing bugs, or adding new features, feel free to check out the GitHub repository and submit a pull request. Whether you're a seasoned developer or new to open source, your contributions can make a difference!