allow appending of listbar items while detached. fixes #148.

This commit is contained in:
Christopher Jeffrey 2015-07-17 18:52:07 -07:00
parent 67b6674558
commit 72ddc05fd1
2 changed files with 11 additions and 4 deletions

View File

@ -157,14 +157,19 @@ Listbar.prototype.addItem =
Listbar.prototype.appendItem = function(item, callback) { Listbar.prototype.appendItem = function(item, callback) {
var self = this var self = this
, prev = this.items[this.items.length - 1] , prev = this.items[this.items.length - 1]
, drawn = prev ? prev.aleft + prev.width : 0 , drawn
, cmd , cmd
, title , title
, len; , len;
if (!this.parent) {
drawn = 0;
} else {
drawn = prev ? prev.aleft + prev.width : 0
if (!this.screen.autoPadding) { if (!this.screen.autoPadding) {
drawn += this.ileft; drawn += this.ileft;
} }
}
if (typeof item === 'object') { if (typeof item === 'object') {
cmd = item; cmd = item;

View File

@ -18,7 +18,7 @@ var box = blessed.box({
}); });
var bar = blessed.listbar({ var bar = blessed.listbar({
parent: screen, //parent: screen,
bottom: 0, bottom: 0,
left: 3, left: 3,
right: 3, right: 3,
@ -110,6 +110,8 @@ var bar = blessed.listbar({
} }
}); });
screen.append(bar);
bar.focus(); bar.focus();
screen.key('q', function() { screen.key('q', function() {