diff --git a/lib/tput.js b/lib/tput.js index 707e059..e760375 100644 --- a/lib/tput.js +++ b/lib/tput.js @@ -365,6 +365,14 @@ Tput.prototype._compile = function(val) { echo('"' + c + '"'); } + function push(c) { + expr('(stack.push(v = ' + c + '), v)'); + } + + function pop(c) { + expr((c ? c + ' = ' : '') + 'stack.pop()'); + } + while (val) { // '\e' -> ^[ if (read(/^\\e/i)) { @@ -373,110 +381,39 @@ Tput.prototype._compile = function(val) { } // '^A' -> ^A - // case-insensitive? if (read(/^\^(.)/i)) { - switch (ch.toUpperCase()) { + ch = ch.toUpperCase(); // ? + switch (ch) { case '@': ch = '\\x00'; break; - case 'A': - ch = '\\x01'; - break; - case 'B': - ch = '\\x02'; - break; - case 'C': - ch = '\\x03'; - break; - case 'D': - ch = '\\x04'; - break; - case 'E': - ch = '\\x05'; - break; - case 'F': - ch = '\\x06'; - break; - case 'G': - ch = '\\x07'; - break; - case 'H': - ch = '\\x08'; - break; - case 'I': - ch = '\\x09'; // \t - break; - case 'J': - ch = '\\x0a'; // \n - break; - case 'K': - ch = '\\x0b'; - break; - case 'L': - ch = '\\x0c'; - break; - case 'M': - ch = '\\x0d'; - break; - case 'N': - ch = '\\x0e'; - break; - case 'O': - ch = '\\x0f'; - break; - case 'P': - ch = '\\x10'; - break; - case 'Q': - ch = '\\x11'; - break; - case 'R': - ch = '\\x12'; - break; - case 'S': - ch = '\\x13'; - break; - case 'T': - ch = '\\x14'; - break; - case 'U': - ch = '\\x15'; - break; - case 'V': - ch = '\\x16'; - break; - case 'W': - ch = '\\x17'; - break; - case 'X': - ch = '\\x18'; - break; - case 'Y': - ch = '\\x19'; - break; - case 'Z': - ch = '\\x1a'; + case '[': + ch = '\\x1b'; break; case '\\': ch = '\\x1c'; break; + case ']': + ch = '\\x1d'; + break; case '^': ch = '\\x1e'; break; case '_': ch = '\\x1f'; break; - case '[': - ch = '\\x1b'; - break; - case ']': - ch = '\\x1d'; - break; case '?': ch = '\\x7f'; break; default: - ch = '\\' + ch; + if (ch >= 'A' && ch <= 'Z') { + ch = ch.charCodeAt(0) - 64; + ch = ch.toString(16); + if (ch.length < 2) ch = '0' + ch; + ch = '\\x' + ch; + } else { + ch = ''; + } break; } print(ch);