key->prefix for listbar. misc.

This commit is contained in:
Christopher Jeffrey 2014-01-11 21:02:19 -06:00
parent 3766ffaa38
commit 4cebb15918
2 changed files with 20 additions and 4 deletions

View File

@ -5887,6 +5887,10 @@ Listbar.prototype.appendItem = function(item, callback) {
};
}
if (cmd.keys && cmd.keys[0]) {
cmd.prefix = cmd.keys[0];
}
title = (cmd.prefix != null ? '{light-black-fg}'
+ cmd.prefix
+ '{/light-black-fg}'
@ -5941,7 +5945,16 @@ Listbar.prototype.appendItem = function(item, callback) {
if (cmd.callback) {
//el.on('press', cmd.callback);
if (cmd.keys) {
this.screen.key(cmd.keys, cmd.callback);
this.screen.key(cmd.keys, function(ch, key) {
self.emit('action', el, self.selected);
self.emit('select', el, self.selected);
//el.press();
if (el._.cmd.callback) {
el._.cmd.callback();
}
self.select(el);
self.screen.render();
});
}
}

View File

@ -46,9 +46,12 @@ var bar = blessed.listbar({
}
},
commands: {
'one': function() {
'one': {
keys: ['a'],
callback: function() {
box.setContent('Pressed one.');
screen.render();
}
},
'two': function() {
box.setContent('Pressed two.');