From 4cebb15918bf2629f40c770ea634242137bd1bc9 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 11 Jan 2014 21:02:19 -0600 Subject: [PATCH] key->prefix for listbar. misc. --- lib/widget.js | 15 ++++++++++++++- test/widget-listbar.js | 9 ++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 34b7605..50f5c86 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -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(); + }); } } diff --git a/test/widget-listbar.js b/test/widget-listbar.js index ab34dea..4fe45c8 100644 --- a/test/widget-listbar.js +++ b/test/widget-listbar.js @@ -46,9 +46,12 @@ var bar = blessed.listbar({ } }, commands: { - 'one': function() { - box.setContent('Pressed one.'); - screen.render(); + 'one': { + keys: ['a'], + callback: function() { + box.setContent('Pressed one.'); + screen.render(); + } }, 'two': function() { box.setContent('Pressed two.');