An open API service indexing awesome lists of open source software.

https://github.com/ddosnotification/interactive-cli-menu

A sleek and customizable CLI menu with arrow key navigation and actions. No external dependencies!
https://github.com/ddosnotification/interactive-cli-menu

cli cli-navigation cli-tool command-line command-line-interface interactive menu node-cli nodejs nodejs-menu npm-package terminal terminal-ui ux-design

Last synced: 4 months ago
JSON representation

A sleek and customizable CLI menu with arrow key navigation and actions. No external dependencies!

Awesome Lists containing this project

README

          

# ๐ŸŒŸ interactive-cli-menu

![npm version](https://img.shields.io/npm/v/interactive-cli-menu)
![downloads](https://img.shields.io/npm/dm/interactive-cli-menu)
![GitHub stars](https://img.shields.io/github/stars/ddosnotification/interactive-cli-menu)

**interactive-cli-menu** is a sleek, modern, and customizable NPM package for creating interactive CLI menus. It supports smooth arrow key navigation, actionable items, and beautiful terminal UIโ€”all without external dependencies! Perfect for making your command-line tools pop! ๐ŸŽ‰

---

## ๐Ÿš€ Features

- ๐Ÿ”ผ **Arrow Key Navigation**: Effortlessly navigate menus with the up/down arrows.
- ๐ŸŽจ **Customizable Styling**: Choose colors, widths, borders, and more.
- โšก **Actionable Items**: Attach custom actions to menu selections.
- ๐Ÿชถ **Lightweight**: No external dependenciesโ€”100% native Node.js.
- ๐Ÿ›‘ **Graceful Exit**: Cleanly handles `Ctrl+C` to terminate.

---

## ๐Ÿ“ฆ Installation

Install via NPM:

```bash
npm install interactive-cli-menu
```

---

## ๐Ÿ› ๏ธ Usage

### โœจ Simple Example

```javascript
const { createMenu } = require('interactive-cli-menu');

const menu = createMenu({
title: '๐Ÿ” Main Menu',
width: 50,
borderColor: 36, // Cyan
highlightColor: 33, // Yellow
textColor: 37, // White
items: [
{ label: '๐Ÿ” Search', action: () => console.log('Searching... ๐Ÿ”Ž') },
{ label: 'โš™๏ธ Settings', action: () => console.log('Opening settings... ๐Ÿ› ๏ธ') },
{ label: 'โŒ Exit', action: () => console.log('Goodbye! ๐Ÿ‘‹') }
]
});

menu.render();
```

### ๐Ÿ–ฅ๏ธ Output

```
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
๐Ÿ” Main Menu
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

๐Ÿ” Search
> โš™๏ธ Settings
โŒ Exit

โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
```

### Interact:
- Use **โฌ†๏ธ Up** and **โฌ‡๏ธ Down** to navigate.
- Press **โŽ Enter** to select.

---

## ๐ŸŽจ API

### `createMenu(options)`

#### `options` (object)

| Option | Type | Default | Description |
|------------------|----------|---------------|-----------------------------------------------------------------------------|
| `title` | `string` | `'Menu'` | Title displayed at the top of the menu. |
| `width` | `number` | `60` | Width of the menu in characters. |
| `borderColor` | `number` | `90` (Gray) | ANSI color code for the border. |
| `highlightColor` | `number` | `34` (Blue) | ANSI color code for the selected menu item. |
| `textColor` | `number` | `37` (White) | ANSI color code for unselected menu items. |
| `items` | `array` | `[]` | Array of menu items (see below). |

---

### Menu Items (`items`)

Each item is an object with the following properties:

| Property | Type | Description |
|------------|------------|--------------------------------------------------------|
| `label` | `string` | The text displayed for the menu item (supports emojis).|
| `action` | `function` | The function executed when the item is selected. |

---

## ๐ŸŒŸ Advanced Example: Dynamic Menus with Emojis

```javascript
const { createMenu } = require('interactive-cli-menu');

let items = [
{ label: '๐Ÿ“„ View Files', action: () => console.log('Listing files... ๐Ÿ—‚๏ธ') },
{ label: 'โž• Add Item', action: () => console.log('Adding item... โœ…') },
{ label: 'โŒ Exit', action: () => console.log('Goodbye! ๐Ÿ‘‹') }
];

const menu = createMenu({
title: '๐Ÿ› ๏ธ My CLI Tool',
width: 60,
borderColor: 35, // Magenta
highlightColor: 32, // Green
textColor: 37, // White
items
});

menu.render();
```

---

## ๐Ÿ›ฃ๏ธ Roadmap

๐Ÿ”ฎ Future Enhancements:
- ๐Ÿ“‚ **Nested Menus**: Add support for multi-level menus.
- ๐ŸŒˆ **Extended Themes**: More built-in color schemes and styles.
- ๐Ÿ•ต๏ธ **Search**: Enable searchable menus for longer lists.
- โŒจ๏ธ **Custom Keybindings**: Allow custom navigation keys.

---

## ๐Ÿ™Œ Contributing

We โค๏ธ contributions! If you find a bug or have an idea for improvement, feel free to [open an issue](https://github.com/ddosnotification/interactive-cli-menu/issues) or submit a pull request.

---

## ๐Ÿ“„ License

**interactive-cli-menu** is open-source and available under the [MIT License](https://opensource.org/licenses/MIT).

---

โœจ **Make your CLI tools stylish and user-friendly with interactive-cli-menu!** ๐ŸŒŸ