https://github.com/tj/node-term-list
Interactive terminal list for nodejs
https://github.com/tj/node-term-list
Last synced: 9 months ago
JSON representation
Interactive terminal list for nodejs
- Host: GitHub
- URL: https://github.com/tj/node-term-list
- Owner: tj
- Created: 2013-07-18T15:57:28.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-01-01T20:05:07.000Z (about 12 years ago)
- Last Synced: 2025-03-28T16:51:24.602Z (10 months ago)
- Language: JavaScript
- Size: 142 KB
- Stars: 125
- Watchers: 3
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# term-list
Renders an interactive list to the terminal that users
can navigate using the arrow keys. Developers can bind
to "keypress" events to support removal or opening of items etc.

## Installation
```
$ npm install term-list
```
## Example
A fully interactive list demonstrating removal via backspace,
and opening of the websites via the return key.
```js
var List = require('term-list');
var exec = require('child_process').exec;
var list = new List({ marker: '\033[36m› \033[0m', markerLength: 2 });
list.add('http://google.com', 'Google');
list.add('http://yahoo.com', 'Yahoo');
list.add('http://cloudup.com', 'Cloudup');
list.add('http://github.com', 'Github');
list.start();
list.on('keypress', function(key, item){
switch (key.name) {
case 'return':
exec('open ' + item);
list.stop();
console.log('opening %s', item);
break;
case 'backspace':
list.remove(list.selected);
break;
}
});
list.on('empty', function(){
list.stop();
});
```
### API
- [List()](#list)
- [List.add()](#listaddidstringlabelstring)
- [List.remove()](#listremoveidstring)
- [List.at()](#listatinumber)
- [List.select()](#listselectidstring)
- [List.draw()](#listdraw)
- [List.up()](#listup)
- [List.down()](#listdown)
- [List.stop()](#liststop)
- [List.start()](#liststart)
### List()
Initialize a new `List` with `opts`:
- `marker` optional marker string defaulting to '› '
- `markerLength` optional marker length, otherwise marker.length is used
### List.add(id:String, label:String)
Add item `id` with `label`.
### List.remove(id:String)
Remove item `id`.
### List.at(i:Number)
Return item at `i`.
### List.select(id:String)
Select item `id`.
### List.draw()
Re-draw the list.
### List.up()
Select the previous item if any.
### List.down()
Select the next item if any.
### List.stop()
Reset state and stop the list.
### List.start()
Start the list.
## License
MIT