This commit is contained in:
Christopher Jeffrey 2013-02-18 11:00:44 -06:00
parent d35e49afb0
commit ef991d5a26

View File

@ -296,22 +296,11 @@ Tput.prototype._compile = function(val) {
return function() {};
}
// e.g.
// set_attributes: '%?%p9%t\u001b(0%e\u001b(B%;\u001b[0%?%p6%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;%?%p7%t;8%;m',
// cursor_address: '\u001b[%i%p1%d;%p2%dH',
// column_address: '\u001b[%i%p1%dG',
// change_scroll_region: '\u001b[%i%p1%d;%p2%dr',
// CSI Ps ; Ps r
// CSI ? Pm r
//var code = 'var dyn = {}, stat = {}, stack = [], out = []; out.push("';
var ch, op, i, v, cap;
var code = 'var v, dyn = {}, stat = {}, stack = [], out = []; function o(a){out.push(a);return a}'
, buff = '';
// man terminfo, around line 940
function b() {
function clear() {
if (buff) {
code += 'o("';
code += buff.replace(/([\r\n"])/g, '\\$1');
@ -325,7 +314,7 @@ Tput.prototype._compile = function(val) {
if (!cap) return;
val = val.substring(cap[0].length);
ch = op = i = v = cap[1];
b();
clear();
return cap;
}
@ -501,7 +490,6 @@ Tput.prototype._compile = function(val) {
continue;
}
// man terminfo, around page 1034
// %% outputs `%'
if (exec(/^%%/g)) {
code += 'o("';
@ -661,21 +649,18 @@ Tput.prototype._compile = function(val) {
// written on one line. The -f option splits the string into lines with
// the parts indented.
if (exec(/^%\?/g)) {
//code += '"); if (';
if (code[code.length-1] === ',') code = code.slice(0, -1);
code += ';if (';
continue;
}
if (exec(/^%t/g)) {
//code += ') { out.push("';
if (code[code.length-1] === ',') code = code.slice(0, -1);
code += ') {';
continue;
}
if (exec(/^%e/g)) {
//code += '"); } else { out.push("';
if (code[code.length-1] === ',') code = code.slice(0, -1);
var end = val.indexOf('%;');
var els = val.indexOf('%e');
@ -690,7 +675,6 @@ Tput.prototype._compile = function(val) {
}
if (exec(/^%;/g)) {
//code += '"); } out.push("';
if (code[code.length-1] === ',') code = code.slice(0, -1);
code += '}';
continue;
@ -728,10 +712,9 @@ Tput.prototype._compile = function(val) {
val = val.substring(1);
}
b();
clear();
if (code[code.length-1] === ',') code = code.slice(0, -1);
//code = code.replace(/(;|})/g, '\n$1\n');
code += ';return out.join("");';
console.log(code.replace(/\x1b/g, '\\x1b'));
@ -739,8 +722,8 @@ Tput.prototype._compile = function(val) {
try {
return new Function('params', code);
} catch (e) {
//console.log(JSON.stringify(e.stack).replace(/\\n/g, '\n'));
console.log(e.stack.replace(/\x1b/g, '\\x1b'));
e.stack = e.stack.replace(/\x1b/g, '\\x1b');
throw e;
}
};