fix a few commands.

This commit is contained in:
Christopher Jeffrey 2013-02-17 14:46:01 -06:00
parent 80b330a2be
commit 1d26b0a6c1

View File

@ -273,7 +273,7 @@ Tput.prototype.compile = function(key) {
}); });
Object.keys(info.all).forEach(function(key) { Object.keys(info.all).forEach(function(key) {
console.log('Compiling key: ' + JSON.stringify(info.all[key])); console.log('Compiling ' + key + ': ' + JSON.stringify(info.all[key]));
self.methods[key] = self._compile(info.all[key]); self.methods[key] = self._compile(info.all[key]);
}); });
}; };
@ -305,13 +305,15 @@ Tput.prototype._compile = function(val) {
// CSI ? Pm r // CSI ? Pm r
//var code = 'var dyn = {}, stat = {}, stack = [], out = []; out.push("'; //var code = 'var dyn = {}, stat = {}, stack = [], out = []; out.push("';
var ch, op, i; var ch, op, i, 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 // man terminfo, around line 940
function b() { function b() {
//val = val.substring(cap[0].length);
//ch = op = i = cap[1];
if (buff) { if (buff) {
code += 'o("'; code += 'o("';
code += buff.replace(/([\r\n"])/g, '\\$1'); code += buff.replace(/([\r\n"])/g, '\\$1');
@ -321,12 +323,15 @@ Tput.prototype._compile = function(val) {
} }
while (val) { while (val) {
// instead calling b() all over, do:
// if (cap) b();
// '\e' -> ^[ // '\e' -> ^[
if (cap = /^\\e/gi.exec(val)) { if (cap = /^\\e/gi.exec(val)) {
b(); b();
val = val.substring(cap[0].length); val = val.substring(cap[0].length);
code += 'o("'; code += 'o("';
code += '\x1b'; code += '\\x1b';
code += '"),'; code += '"),';
continue; continue;
} }
@ -339,103 +344,103 @@ Tput.prototype._compile = function(val) {
code += 'o("'; code += 'o("';
switch (ch) { switch (ch) {
case '@': case '@':
code += '\x00'; code += '\\x00';
break; break;
case 'A': case 'A':
code += '\x01'; code += '\\x01';
break; break;
case 'B': case 'B':
code += '\x02'; code += '\\x02';
break; break;
case 'C': case 'C':
code += '\x03'; code += '\\x03';
break; break;
case 'D': case 'D':
code += '\x04'; code += '\\x04';
break; break;
case 'E': case 'E':
code += '\x05'; code += '\\x05';
break; break;
case 'F': case 'F':
code += '\x06'; code += '\\x06';
break; break;
case 'G': case 'G':
code += '\x07'; code += '\\x07';
break; break;
case 'H': case 'H':
code += '\x08'; code += '\\x08';
break; break;
case 'I': case 'I':
code += '\x09'; // \t code += '\\x09'; // \t
break; break;
case 'J': case 'J':
code += '\x0a'; // \n code += '\\x0a'; // \n
break; break;
case 'K': case 'K':
code += '\x0b'; code += '\\x0b';
break; break;
case 'L': case 'L':
code += '\x0c'; code += '\\x0c';
break; break;
case 'M': case 'M':
code += '\x0d'; code += '\\x0d';
break; break;
case 'N': case 'N':
code += '\x0e'; code += '\\x0e';
break; break;
case 'O': case 'O':
code += '\x0f'; code += '\\x0f';
break; break;
case 'P': case 'P':
code += '\x10'; code += '\\x10';
break; break;
case 'Q': case 'Q':
code += '\x11'; code += '\\x11';
break; break;
case 'R': case 'R':
code += '\x12'; code += '\\x12';
break; break;
case 'S': case 'S':
code += '\x13'; code += '\\x13';
break; break;
case 'T': case 'T':
code += '\x14'; code += '\\x14';
break; break;
case 'U': case 'U':
code += '\x15'; code += '\\x15';
break; break;
case 'V': case 'V':
code += '\x16'; code += '\\x16';
break; break;
case 'W': case 'W':
code += '\x17'; code += '\\x17';
break; break;
case 'X': case 'X':
code += '\x18'; code += '\\x18';
break; break;
case 'Y': case 'Y':
code += '\x19'; code += '\\x19';
break; break;
case 'Z': case 'Z':
code += '\x1a'; code += '\\x1a';
break; break;
case '\\': case '\\':
code += '\x1c'; code += '\\x1c';
break; break;
case '^': case '^':
code += '\x1e'; code += '\\x1e';
break; break;
case '_': case '_':
code += '\x1f'; code += '\\x1f';
break; break;
case '[': case '[':
code += '\x1b'; code += '\\x1b';
break; break;
case ']': case ']':
code += '\x1d'; code += '\\x1d';
break; break;
case '?': case '?':
code += '\x7f'; code += '\\x7f';
break; break;
} }
code += '"),'; code += '"),';
@ -452,28 +457,32 @@ Tput.prototype._compile = function(val) {
code += 'o("'; code += 'o("';
switch (ch) { switch (ch) {
case 'n': case 'n':
return '\n'; code += '\\n';
case 'l': case 'l':
return '\l'; code += '\\l'; // ?
case 'r': case 'r':
return '\r'; code += '\\r';
case 't': case 't':
return '\t'; code += '\\t';
case 'b': case 'b':
return '\b'; code += '\\x08';
case 'f': case 'f':
return '\f'; code += '\\x0c';
//case 'v':
// return '\\x0b';
//case 'a':
// return '\\x07':
case 's': case 's':
return '\s'; code += '\\s'; // ?
case '\\': case '\\':
return '\\'; code += '\\\\';
case ',': case ',':
return ','; code += ',';
case ';': case ';':
return ';'; code += ';';
case '0': case '0':
//return '\0'; //return '\0';
return '\200'; code += '\\200';
} }
code += '"),'; code += '"),';
continue; continue;
@ -485,7 +494,8 @@ Tput.prototype._compile = function(val) {
val = val.substring(cap[0].length); val = val.substring(cap[0].length);
ch = cap[1]; ch = cap[1];
code += 'o("'; code += 'o("';
code += String.fromCharCode(parseInt(ch, 8)); code += '\\' + ch;
//code += String.fromCharCode(parseInt(ch, 8));
code += '"),'; code += '"),';
continue; continue;
} }
@ -666,6 +676,7 @@ Tput.prototype._compile = function(val) {
b(); b();
val = val.substring(cap[0].length); val = val.substring(cap[0].length);
op = cap[1]; op = cap[1];
if (code[code.length-1] === ',') code = code.slice(0, -1);
code += op === ' A ' ? ' && ' : ' || '; code += op === ' A ' ? ' && ' : ' || ';
continue; continue;
} }