-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
48 lines (43 loc) · 1.02 KB
/
example.js
File metadata and controls
48 lines (43 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var ScrollableList = require('./');
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();
});