term-list

interactive terminal lists

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.

$ npm install term-list

A fully interactive list demonstrating removal via backspace, and opening of the websites via the return key.

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(keyitem){
  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();
});

Initialize a new List with opts:

  • marker optional marker string defaulting to '› '
  • markerLength optional marker length, otherwise marker.length is used

Add item id with label.

Remove item id.

Return item at i.

Select item id.

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.

MIT