mirror of
https://github.com/embarklabs/neo-blessed.git
synced 2025-02-09 09:34:47 +00:00
itemBg, style object, el.sattr.
This commit is contained in:
parent
db365a2228
commit
7e238a470e
110
lib/widget.js
110
lib/widget.js
@ -1438,6 +1438,33 @@ Element.prototype.__proto__ = Node.prototype;
|
|||||||
|
|
||||||
Element.prototype.type = 'element';
|
Element.prototype.type = 'element';
|
||||||
|
|
||||||
|
Element.prototype.sattr = function(obj, fg, bg) {
|
||||||
|
var bold = obj.bold
|
||||||
|
, underline = obj.underline
|
||||||
|
, blink = obj.blink
|
||||||
|
, inverse = obj.inverse
|
||||||
|
, invisible = obj.invisible;
|
||||||
|
|
||||||
|
// This used to be a loop, but I decided
|
||||||
|
// to unroll it for performance's sake.
|
||||||
|
if (typeof bold === 'function') bold = bold(this);
|
||||||
|
if (typeof underline === 'function') underline = underline(this);
|
||||||
|
if (typeof blink === 'function') blink = blink(this);
|
||||||
|
if (typeof inverse === 'function') inverse = inverse(this);
|
||||||
|
if (typeof invisible === 'function') invisible = invisible(this);
|
||||||
|
|
||||||
|
if (typeof fg === 'function') fg = fg(this);
|
||||||
|
if (typeof bg === 'function') bg = bg(this);
|
||||||
|
|
||||||
|
return ((((invisible ? 16 : 0) << 18)
|
||||||
|
| ((inverse ? 8 : 0) << 18)
|
||||||
|
| ((blink ? 4 : 0) << 18)
|
||||||
|
| ((underline ? 2 : 0) << 18))
|
||||||
|
| ((bold ? 1 : 0) << 18)
|
||||||
|
| (colors.convert(fg) << 9))
|
||||||
|
| colors.convert(bg);
|
||||||
|
};
|
||||||
|
|
||||||
Element.prototype.onScreenEvent = function(type, listener) {
|
Element.prototype.onScreenEvent = function(type, listener) {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (this.parent) {
|
if (this.parent) {
|
||||||
@ -1988,10 +2015,10 @@ Box.prototype.render = function(stop) {
|
|||||||
if (stop) return ret;
|
if (stop) return ret;
|
||||||
|
|
||||||
battr = this.border
|
battr = this.border
|
||||||
? sattr(this.border, this.border.fg, this.border.bg)
|
? this.sattr(this.border, this.border.fg, this.border.bg)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
||||||
dattr = sattr(this, this.fg, this.bg);
|
dattr = this.sattr(this, this.fg, this.bg);
|
||||||
attr = dattr;
|
attr = dattr;
|
||||||
|
|
||||||
// Check previous line for escape codes.
|
// Check previous line for escape codes.
|
||||||
@ -2084,7 +2111,7 @@ outer:
|
|||||||
cell = lines[yi] && lines[yi][xi];
|
cell = lines[yi] && lines[yi][xi];
|
||||||
if (cell) {
|
if (cell) {
|
||||||
ch = this.scrollbar.ch || ' ';
|
ch = this.scrollbar.ch || ' ';
|
||||||
attr = sattr(this,
|
attr = this.sattr(this,
|
||||||
this.scrollbar.fg || this.fg,
|
this.scrollbar.fg || this.fg,
|
||||||
this.scrollbar.bg || this.bg);
|
this.scrollbar.bg || this.bg);
|
||||||
if (attr !== cell[0] || ch !== cell[1]) {
|
if (attr !== cell[0] || ch !== cell[1]) {
|
||||||
@ -2461,6 +2488,38 @@ function List(options) {
|
|||||||
this.selectedInverse = options.selectedInverse;
|
this.selectedInverse = options.selectedInverse;
|
||||||
this.selectedInvisible = options.selectedInvisible;
|
this.selectedInvisible = options.selectedInvisible;
|
||||||
|
|
||||||
|
this.itemBg = cens(options.itemBg);
|
||||||
|
this.itemFg = cens(options.itemFg);
|
||||||
|
this.itemBold = options.itemBold;
|
||||||
|
this.itemUnderline = options.itemUnderline;
|
||||||
|
this.itemBlink = options.itemBlink;
|
||||||
|
this.itemInverse = options.itemInverse;
|
||||||
|
this.itemInvisible = options.itemInvisible;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (!this.style.selected) {
|
||||||
|
this.style.selected = {};
|
||||||
|
this.style.selected.bg = cens(options.selectedBg);
|
||||||
|
this.style.selected.fg = cens(options.selectedFg);
|
||||||
|
this.style.selected.bold = options.selectedBold;
|
||||||
|
this.style.selected.underline = options.selectedUnderline;
|
||||||
|
this.style.selected.blink = options.selectedBlink;
|
||||||
|
this.style.selected.inverse = options.selectedInverse;
|
||||||
|
this.style.selected.invisible = options.selectedInvisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.style.item) {
|
||||||
|
this.style.item = {};
|
||||||
|
this.style.item.bg = cens(options.itemBg);
|
||||||
|
this.style.item.fg = cens(options.itemFg);
|
||||||
|
this.style.item.bold = options.itemBold;
|
||||||
|
this.style.item.underline = options.itemUnderline;
|
||||||
|
this.style.item.blink = options.itemBlink;
|
||||||
|
this.style.item.inverse = options.itemInverse;
|
||||||
|
this.style.item.invisible = options.itemInvisible;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
this.mouse = options.mouse || false;
|
this.mouse = options.mouse || false;
|
||||||
|
|
||||||
if (options.items) {
|
if (options.items) {
|
||||||
@ -2609,6 +2668,22 @@ List.prototype.add = function(item) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
['bg', 'fg', 'bold', 'underline',
|
||||||
|
'blink', 'inverse', 'invisible'].forEach(function(name) {
|
||||||
|
// TODO: Move all specific options to their own object namespaces.
|
||||||
|
var iname = 'item' + name[0].toUpperCase() + name.substring(1)
|
||||||
|
, sname = 'selected' + name[0].toUpperCase() + name.substring(1);
|
||||||
|
options[name] = function() {
|
||||||
|
var attr = self.items[self.selected] === item
|
||||||
|
? self[sname]
|
||||||
|
: self[iname];
|
||||||
|
if (typeof attr === 'function') attr = attr(item);
|
||||||
|
return attr;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
var item = new Box(options);
|
var item = new Box(options);
|
||||||
|
|
||||||
this.append(item);
|
this.append(item);
|
||||||
@ -3282,7 +3357,7 @@ ProgressBar.prototype.render = function(stop) {
|
|||||||
yi = yi + ((yl - yi) - (((yl - yi) * (this.filled / 100)) | 0));
|
yi = yi + ((yl - yi) - (((yl - yi) * (this.filled / 100)) | 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
dattr = sattr(this, this.barFg, this.barBg);
|
dattr = this.sattr(this, this.barFg, this.barBg);
|
||||||
|
|
||||||
this.screen.fillRegion(dattr, this.ch, xi, xl, yi, yl);
|
this.screen.fillRegion(dattr, this.ch, xi, xl, yi, yl);
|
||||||
|
|
||||||
@ -4226,33 +4301,6 @@ function hsort(obj) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function sattr(obj, fg, bg) {
|
|
||||||
var bold = obj.bold
|
|
||||||
, underline = obj.underline
|
|
||||||
, blink = obj.blink
|
|
||||||
, inverse = obj.inverse
|
|
||||||
, invisible = obj.invisible;
|
|
||||||
|
|
||||||
// This used to be a loop, but I decided
|
|
||||||
// to unroll it for performance's sake.
|
|
||||||
if (typeof bold === 'function') bold = bold(obj);
|
|
||||||
if (typeof underline === 'function') underline = underline(obj);
|
|
||||||
if (typeof blink === 'function') blink = blink(obj);
|
|
||||||
if (typeof inverse === 'function') inverse = inverse(obj);
|
|
||||||
if (typeof invisible === 'function') invisible = invisible(obj);
|
|
||||||
|
|
||||||
if (typeof fg === 'function') fg = fg(obj);
|
|
||||||
if (typeof bg === 'function') bg = bg(obj);
|
|
||||||
|
|
||||||
return ((((invisible ? 16 : 0) << 18)
|
|
||||||
| ((inverse ? 8 : 0) << 18)
|
|
||||||
| ((blink ? 4 : 0) << 18)
|
|
||||||
| ((underline ? 2 : 0) << 18))
|
|
||||||
| ((bold ? 1 : 0) << 18)
|
|
||||||
| (colors.convert(fg) << 9))
|
|
||||||
| colors.convert(bg);
|
|
||||||
}
|
|
||||||
|
|
||||||
function cens(color) {
|
function cens(color) {
|
||||||
return color != null
|
return color != null
|
||||||
? color
|
? color
|
||||||
|
Loading…
x
Reference in New Issue
Block a user