fix a few commands.

This commit is contained in:
Christopher Jeffrey 2013-02-17 14:46:01 -06:00
parent 80b330a2be
commit 1d26b0a6c1
1 changed files with 59 additions and 48 deletions

View File

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