enable new parseTags method. clean up old code.

This commit is contained in:
Christopher Jeffrey 2013-07-28 14:18:28 -05:00
parent 084f28fcff
commit 3bcbd9b39f
1 changed files with 9 additions and 56 deletions

View File

@ -1933,22 +1933,11 @@ Element.prototype.parseContent = function() {
// Convert `{red-fg}foo{/red-fg}` to `\x1b[31mfoo\x1b[39m`.
Element.prototype._parseTags = function(text) {
if (!this.parseTags) return text;
var program = this.screen.program;
return text.replace(/{(\/?)([\w\-,;!#]*)}/g, function(tag, slash, color) {
if (!color) return slash ? '\x1b[m' : tag;
color = color.replace(/-/g, ' ');
var result = program._attr(color, !slash);
return result != null ? result : tag;
});
};
// Convert `{red-fg}foo{/red-fg}` to `\x1b[31mfoo\x1b[39m`.
Element.prototype._parseTags_ = function(text) {
if (!this.parseTags) return text;
if (!/{\/?[\w\-,;!#]*}/.test(text)) return text;
var out = ''
var program = this.screen.program
, out = ''
, state
, bg = []
, fg = []
@ -1970,21 +1959,21 @@ Element.prototype._parseTags_ = function(text) {
if (slash) {
if (!param) {
out += this._attr('normal');
out += program._attr('normal');
bg.length = 0;
fg.length = 0;
flag.length = 0;
} else {
attr = this._attr(param, false);
attr = program._attr(param, false);
if (attr == null) {
out += cap[0];
} else {
if (param !== state[state.length-1]) {
throw new Error('Misnested tags.');
}
// if (param !== state[state.length-1]) {
// throw new Error('Misnested tags.');
// }
state.pop();
if (state.length) {
out += this._attr(state[state.length-1]);
out += program._attr(state[state.length-1]);
} else {
out += attr;
}
@ -1994,7 +1983,7 @@ Element.prototype._parseTags_ = function(text) {
if (!param) {
out += cap[0];
} else {
attr = this._attr(param);
attr = program._attr(param);
if (attr == null) {
out += cap[0];
} else {
@ -2020,42 +2009,6 @@ Element.prototype._parseTags_ = function(text) {
return out;
};
Element.prototype._attr = function(param, val) {
return this.screen.program._attr(param, val);
};
// If we want the resetting of attributes to the element's current style to
// *only* be for tags, we can do this and set the codes above to start at 9000:
Element.prototype._attr_ = function(param, val) {
var param = this.screen.program._attr(param, val)
, i
, c;
if (!param) return param;
param = param.slice(2, -1).split(';');
if (!param[0]) param[0] = '0';
for (i = 0; i < param.length; i++) {
c = +param[i] || 0;
switch (c) {
case 0: // reset
case 22: // reset bold
case 24: // reset underline
case 25: // reset blink
case 27: // reset inverse
case 28: // reset invisible
case 39: // reset fg
case 49: // reset bg
case 100: // reset fg/bg
param[i] = 9000 + c;
break;
}
}
return '\x1b[' + out.join(';') + 'm';
};
Element.prototype._parseAttr = function(lines) {
var dattr = this.sattr(this.style, this.style.fg, this.style.bg)
, attr = dattr