mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-01-11 03:25:45 +00:00
remove old listbar.setItems.
This commit is contained in:
parent
6ed2451e36
commit
66933f63b6
@ -5788,97 +5788,6 @@ Listbar.prototype.__defineGetter__('selected', function() {
|
||||
return this.leftBase + this.leftOffset;
|
||||
});
|
||||
|
||||
Listbar.prototype.setItems = function(commands) {
|
||||
if (Array.isArray(commands)) {
|
||||
commands = commands.reduce(function(obj, text, i) {
|
||||
obj[text] = { prefix: ++i + '' };
|
||||
return obj;
|
||||
}, {});
|
||||
}
|
||||
|
||||
Object.keys(commands).forEach(function(key, i) {
|
||||
var cmd = commands[key];
|
||||
if (typeof cmd === 'function') {
|
||||
commands[key] = { prefix: ++i + '', callback: cmd };
|
||||
}
|
||||
});
|
||||
|
||||
this.ritems = Object.keys(commands);
|
||||
|
||||
this.items.forEach(function(el) {
|
||||
el.detach();
|
||||
});
|
||||
this.items = [];
|
||||
|
||||
var self = this
|
||||
, drawn = 0;
|
||||
|
||||
this.commands = commands;
|
||||
|
||||
Object.keys(commands).forEach(function(name) {
|
||||
var cmd = commands[name]
|
||||
, title
|
||||
, len
|
||||
, item;
|
||||
|
||||
title = (cmd.prefix != null ? '{light-black-fg}'
|
||||
+ cmd.prefix
|
||||
+ '{/light-black-fg}'
|
||||
+ ':' : '')
|
||||
+ name;
|
||||
|
||||
len = ((cmd.prefix != null ? cmd.prefix + ':' : '') + name).length;
|
||||
|
||||
var options = {
|
||||
parent: self,
|
||||
top: 0,
|
||||
left: drawn + 1,
|
||||
height: 1,
|
||||
content: title,
|
||||
width: len + 2,
|
||||
align: 'center',
|
||||
autoFocus: false,
|
||||
tags: true,
|
||||
mouse: true,
|
||||
style: merge({}, self.style.item)
|
||||
//style: {}
|
||||
};
|
||||
|
||||
if (self.screen.autoPadding) {
|
||||
;
|
||||
}
|
||||
|
||||
['bg', 'fg', 'bold', 'underline',
|
||||
'blink', 'inverse', 'invisible'].forEach(function(name) {
|
||||
options.style[name] = function() {
|
||||
var attr = self.items[self.selected] === item
|
||||
? self.style.selected[name]
|
||||
: self.style.item[name];
|
||||
if (typeof attr === 'function') attr = attr(item);
|
||||
return attr;
|
||||
};
|
||||
});
|
||||
|
||||
item = new Button(options);
|
||||
|
||||
self._[name] = item;
|
||||
cmd.element = item;
|
||||
self.items.push(item);
|
||||
item._.cmd = cmd;
|
||||
|
||||
if (cmd.callback) {
|
||||
item.on('press', cmd.callback);
|
||||
if (cmd.keys) {
|
||||
self.screen.key(cmd.keys, cmd.callback);
|
||||
}
|
||||
}
|
||||
|
||||
drawn += len + 3;
|
||||
});
|
||||
|
||||
this.select(0);
|
||||
};
|
||||
|
||||
Listbar.prototype.setItems = function(commands) {
|
||||
var self = this;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user