0.0.10 • Published 7 years ago

terminal-item-menu v0.0.10

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

terminal-item-menu

A simple, searchable menu for the terminal.

npm.io

Here's the code for the above gif:

var Menu = require('terminal-item-menu');

var pokeMenu = new Menu({
  header: 'Choose a Pokemon',
  items: [
	  {
	  	value: 'bulbasaur',
	  	text: '#01 Bulbasaur'
	  },
	  {
	  	value: 'charmander',
	  	text: '#04 Charmander'
	  },
	  {
	  	value: 'squirtle',
	  	text: '#07 Squirtle'
	  },
	  {
	  	value: 'pikachu',
	  	text: '#025 Pikachu'
	  }
  ]
});

pokeMenu.start().then(val => console.log('You chose ' + val));

##Docs

####Menu Options

OptionTypeDefaultDescriptionRequired
caseInsensitivebooleanfalseIf true, the ctrl+r search mode is case insensitive
headerstringnullA header for the menu
itemsarray of MenuItemN/AThe list of menu items
onExitfunctionnullA function that gets called when the menu closes (when an item is selected, or the menu is quit)
onQuitfunctionnullA function that gets called when the user quits the menu with control+c
startIndexnumber0The index within the item list of the initially displayed item

####MenuItem

PropertyTypeDefaultDescriptionRequired
onSelectfunction: (selectedValue) => voidnullA function that gets called when the item is selected
textstringMenuItem.valueThe text to be displayed for the item
valuefunctionN/AThe value that gets reported when the item is selected. Is the default displayed text, if the text option is null.

####Menu Instance Properties

PropertyTypeDescription
startfunctionCall this function to display the menu on the screen. It will return a promise that will resolve with the selected item value, or reject if the user quits the menu.

How to Use the Menu

KeyEffect
Up/DownMoves up and down the item list
Ctrl+cCloses the menu or exits out of search mode
Ctrl+r / Ctrl+sEnters search mode. When the user types characters, it will search against the menu items' text field, and display the relevant ones. Hitting Ctrl+r/Ctrl+s again, will cycle between relevant results. Ctrl+c will exit search mode, Enter will exit search mode with the current search item selected.
EnterSelects the current item. In search mode it sets the current search item as the current item and exits search mode.
0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago