Renders an interactive list to the terminal that users can navigate using the arrow keys, similar API with term-list but scrollable, and support header or footer.
$ npm install term-list-scrollable
A fully interactive scrollablelist demonstrating removal via backspace, and opening of the websites via the return key.
var ScrollableList = require('term-list-scrollable');
var exec = require('child_process').exec;
var list = new ScrollableList({
marker: '\033[36m› \033[0m',
markerLength: 2,
viewportSize: 5
});
list.header('Bookmarks');
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.footer('press RETURN to open');
list.start();
setTimeout(function(){
list.add('http://cuteoverload.com', 'Cute Overload');
list.draw();
}, 2000);
setTimeout(function(){
list.add('http://uglyoverload.com', 'Ugly Overload');
list.draw();
}, 4000);
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;
case 'c':
if (key.ctrl) {
list.stop();
process.exit();
}
break;
}
});
list.on('empty', function(){
list.stop();
});- ScrollableList()
- ScrollableList.add()
- ScrollableList.header()
- ScrollableList.footer()
- ScrollableList.remove()
- ScrollableList.at()
- ScrollableList.select()
- ScrollableList.selected()
- ScrollableList.draw()
- ScrollableList.up()
- ScrollableList.down()
- ScrollableList.stop()
- ScrollableList.start()
- ScrollableList.on()
Initialize a new ScrollableList with opts:
markeroptional marker string defaulting to '› 'markerLengthoptional marker length, otherwise marker.length is usedviewportSizeoptional scrollable list size, defualt is 16
Add item id with label.
Set or get header, set header if label provided, or return header item. label with '' will unset it.
Set or get footer, set footer if label provided, or return footer item. label with '' will unset it.
Remove item id.
Return item at i.
Select item id.
Return seleted item.
Re-draw the list.
Select the previous item if any.
Select the next item if any.
Reset state and stop the list.
Start the list.
Bind event listener
MIT