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() {}; 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 ch, op, i, v, cap;
var code = 'var v, dyn = {}, stat = {}, stack = [], out = []; function o(a){out.push(a);return a}' var code = 'var v, dyn = {}, stat = {}, stack = [], out = []; function o(a){out.push(a);return a}'
, buff = ''; , buff = '';
// man terminfo, around line 940 function clear() {
function b() {
if (buff) { if (buff) {
code += 'o("'; code += 'o("';
code += buff.replace(/([\r\n"])/g, '\\$1'); code += buff.replace(/([\r\n"])/g, '\\$1');
@ -325,7 +314,7 @@ Tput.prototype._compile = function(val) {
if (!cap) return; if (!cap) return;
val = val.substring(cap[0].length); val = val.substring(cap[0].length);
ch = op = i = v = cap[1]; ch = op = i = v = cap[1];
b(); clear();
return cap; return cap;
} }
@ -501,7 +490,6 @@ Tput.prototype._compile = function(val) {
continue; continue;
} }
// man terminfo, around page 1034
// %% outputs `%' // %% outputs `%'
if (exec(/^%%/g)) { if (exec(/^%%/g)) {
code += 'o("'; code += 'o("';
@ -661,21 +649,18 @@ Tput.prototype._compile = function(val) {
// written on one line. The -f option splits the string into lines with // written on one line. The -f option splits the string into lines with
// the parts indented. // the parts indented.
if (exec(/^%\?/g)) { if (exec(/^%\?/g)) {
//code += '"); if (';
if (code[code.length-1] === ',') code = code.slice(0, -1); if (code[code.length-1] === ',') code = code.slice(0, -1);
code += ';if ('; code += ';if (';
continue; continue;
} }
if (exec(/^%t/g)) { if (exec(/^%t/g)) {
//code += ') { out.push("';
if (code[code.length-1] === ',') code = code.slice(0, -1); if (code[code.length-1] === ',') code = code.slice(0, -1);
code += ') {'; code += ') {';
continue; continue;
} }
if (exec(/^%e/g)) { if (exec(/^%e/g)) {
//code += '"); } else { out.push("';
if (code[code.length-1] === ',') code = code.slice(0, -1); if (code[code.length-1] === ',') code = code.slice(0, -1);
var end = val.indexOf('%;'); var end = val.indexOf('%;');
var els = val.indexOf('%e'); var els = val.indexOf('%e');
@ -690,7 +675,6 @@ Tput.prototype._compile = function(val) {
} }
if (exec(/^%;/g)) { if (exec(/^%;/g)) {
//code += '"); } out.push("';
if (code[code.length-1] === ',') code = code.slice(0, -1); if (code[code.length-1] === ',') code = code.slice(0, -1);
code += '}'; code += '}';
continue; continue;
@ -728,10 +712,9 @@ Tput.prototype._compile = function(val) {
val = val.substring(1); val = val.substring(1);
} }
b(); clear();
if (code[code.length-1] === ',') code = code.slice(0, -1); if (code[code.length-1] === ',') code = code.slice(0, -1);
//code = code.replace(/(;|})/g, '\n$1\n');
code += ';return out.join("");'; code += ';return out.join("");';
console.log(code.replace(/\x1b/g, '\\x1b')); console.log(code.replace(/\x1b/g, '\\x1b'));
@ -739,8 +722,8 @@ Tput.prototype._compile = function(val) {
try { try {
return new Function('params', code); return new Function('params', code);
} catch (e) { } catch (e) {
//console.log(JSON.stringify(e.stack).replace(/\\n/g, '\n')); e.stack = e.stack.replace(/\x1b/g, '\\x1b');
console.log(e.stack.replace(/\x1b/g, '\\x1b')); throw e;
} }
}; };