minor refactor of el.sattr.

This commit is contained in:
Christopher Jeffrey 2015-04-04 00:26:10 -07:00
parent 861ec57327
commit 7afb791950

View File

@ -1942,10 +1942,7 @@ Screen.prototype._cursorAttr = function(cursor, dattr) {
attr |= 7 << 9;
attr |= 8 << 18;
} else if (typeof cursor.shape === 'object' && cursor.shape) {
cattr = Element.prototype.sattr.call(cursor,
cursor.shape,
cursor.shape.fg,
cursor.shape.bg);
cattr = Element.prototype.sattr.call(cursor, cursor.shape);
if (cursor.shape.bold || cursor.shape.underline
|| cursor.shape.blink || cursor.shape.inverse
@ -2183,12 +2180,18 @@ Element.prototype.__defineGetter__('focused', function() {
return this.screen.focused === this;
});
Element.prototype.sattr = function(obj, fg, bg) {
var bold = obj.bold
, underline = obj.underline
, blink = obj.blink
, inverse = obj.inverse
, invisible = obj.invisible;
Element.prototype.sattr = function(style, fg, bg) {
var bold = style.bold
, underline = style.underline
, blink = style.blink
, inverse = style.inverse
, invisible = style.invisible;
// if (arguments.length === 1) {
if (fg == null && bg == null) {
fg = style.fg;
bg = style.bg;
}
// This used to be a loop, but I decided
// to unroll it for performance's sake.
@ -2425,7 +2428,7 @@ Element.prototype._parseTags = function(text) {
};
Element.prototype._parseAttr = function(lines) {
var dattr = this.sattr(this.style, this.style.fg, this.style.bg)
var dattr = this.sattr(this.style)
, attr = dattr
, attrs = []
, line
@ -3746,7 +3749,7 @@ Element.prototype.render = function() {
this.lpos = coords;
dattr = this.sattr(this.style, this.style.fg, this.style.bg);
dattr = this.sattr(this.style);
attr = dattr;
// If we're in a scrollable text box, check to
@ -3899,8 +3902,7 @@ Element.prototype.render = function() {
// Draw the border.
if (this.border) {
battr = this.sattr(this.style.border,
this.style.border.fg, this.style.border.bg);
battr = this.sattr(this.style.border);
y = yi;
if (coords.notop) y = -1;
for (x = xi; x < xl; x++) {
@ -5957,7 +5959,7 @@ ProgressBar.prototype.render = function() {
yi = yi + ((yl - yi) - (((yl - yi) * (this.filled / 100)) | 0));
}
dattr = this.sattr(this.style.bar, this.style.bar.fg, this.style.bar.bg);
dattr = this.sattr(this.style.bar);
this.screen.fillRegion(dattr, this.pch, xi, xl, yi, yl);
@ -7288,25 +7290,10 @@ Table.prototype.render = function() {
, ry
, i;
var dattr = this.sattr(
this.style,
this.style.fg,
this.style.bg);
var hattr = this.sattr(
this.style.header,
this.style.header.fg,
this.style.header.bg);
var cattr = this.sattr(
this.style.cell,
this.style.cell.fg,
this.style.cell.bg);
var battr = this.sattr(
this.style.border,
this.style.border.fg,
this.style.border.bg);
var dattr = this.sattr(this.style)
, hattr = this.sattr(this.style.header)
, cattr = this.sattr(this.style.cell)
, battr = this.sattr(this.style.border);
var width = coords.xl - coords.xi - this.iwidth / 2
, height = coords.yl - coords.yi - this.iheight / 2;
@ -7596,10 +7583,7 @@ ListTable.prototype.render = function() {
, ry
, i;
var battr = this.sattr(
this.style.border,
this.style.border.fg,
this.style.border.bg);
var battr = this.sattr(this.style.border);
var width = coords.xl - coords.xi - this.iwidth / 2
, height = coords.yl - coords.yi - this.iheight / 2;
@ -7872,7 +7856,7 @@ Terminal.prototype.render = function() {
var ret = this._render();
if (!ret) return;
this.dattr = this.sattr(this.style, this.style.fg, this.style.bg);
this.dattr = this.sattr(this.style);
var xi = ret.xi + this.ileft
, xl = ret.xl - this.iright
@ -8511,8 +8495,8 @@ helpers.textLength = function(text) {
return Element.prototype.textLength.call({ parseTags: true }, text);
};
helpers.attrToBinary = function(obj, fg, bg, target) {
return Element.prototype.sattr.call(target || {}, obj, fg, bg);
helpers.attrToBinary = function(style, element) {
return Element.prototype.sattr.call(element || {}, style);
};
helpers.merge = merge;