mirror of
https://github.com/chjj/blessed.git
synced 2026-02-06 13:51:52 +00:00
tput.js refactor. rename variables.
This commit is contained in:
parent
5e2ca90f04
commit
8f936d00b7
65
lib/tput.js
65
lib/tput.js
@ -526,8 +526,7 @@ Tput.prototype.compile = function(info) {
|
||||
['bools', 'numbers', 'strings'].forEach(function(type) {
|
||||
Object.keys(info[type]).forEach(function(key) {
|
||||
info.all[key] = info[type][key];
|
||||
self._debug('Compiling %s: %s', key, JSON.stringify(info.all[key]));
|
||||
info.methods[key] = self._compile(info.all[key], key, info);
|
||||
info.methods[key] = self._compile(info, key, info.all[key]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -594,7 +593,11 @@ Tput.prototype.inject = function(info) {
|
||||
// See:
|
||||
// ~/ncurses/ncurses/tinfo/lib_tparm.c
|
||||
// ~/ncurses/ncurses/tinfo/comp_scan.c
|
||||
Tput.prototype._compile = function(str, key, info) {
|
||||
Tput.prototype._compile = function(info, key, str) {
|
||||
var self = this;
|
||||
|
||||
this._debug('Compiling %s: %s', key, JSON.stringify(str));
|
||||
|
||||
switch (typeof str) {
|
||||
case 'boolean':
|
||||
return str;
|
||||
@ -629,30 +632,18 @@ Tput.prototype._compile = function(str, key, info) {
|
||||
, code = header
|
||||
, val = str
|
||||
, buff = ''
|
||||
, cap;
|
||||
|
||||
var ch
|
||||
, op
|
||||
, i
|
||||
, v
|
||||
|
||||
var fi
|
||||
, cap
|
||||
, ch
|
||||
, fi
|
||||
, then
|
||||
, els
|
||||
, end;
|
||||
|
||||
function clear() {
|
||||
if (buff) {
|
||||
echo(JSON.stringify(buff).replace(/\\u00([0-9a-fA-F]{2})/g, '\\x$1'));
|
||||
buff = '';
|
||||
}
|
||||
}
|
||||
|
||||
function read(regex, no) {
|
||||
cap = regex.exec(val);
|
||||
if (!cap) return;
|
||||
val = val.substring(cap[0].length);
|
||||
ch = op = i = v = cap[1];
|
||||
ch = cap[1];
|
||||
if (!no) clear();
|
||||
return cap;
|
||||
}
|
||||
@ -681,12 +672,11 @@ Tput.prototype._compile = function(str, key, info) {
|
||||
buff += c;
|
||||
}
|
||||
|
||||
function push(c) {
|
||||
expr('(stack.push(v = ' + c + '), v)');
|
||||
}
|
||||
|
||||
function pop(c) {
|
||||
expr((c ? c + ' = ' : '') + 'stack.pop()');
|
||||
function clear() {
|
||||
if (buff) {
|
||||
echo(JSON.stringify(buff).replace(/\\u00([0-9a-fA-F]{2})/g, '\\x$1'));
|
||||
buff = '';
|
||||
}
|
||||
}
|
||||
|
||||
while (val) {
|
||||
@ -818,28 +808,28 @@ Tput.prototype._compile = function(str, key, info) {
|
||||
// %p[1-9]
|
||||
// push i'th parameter
|
||||
if (read(/^%p([1-9])/)) {
|
||||
expr('(stack.push(v = params[' + (i - 1) + ']), v)');
|
||||
expr('(stack.push(v = params[' + (ch - 1) + ']), v)');
|
||||
continue;
|
||||
}
|
||||
|
||||
// %P[a-z]
|
||||
// set dynamic variable [a-z] to pop()
|
||||
if (read(/^%P([a-z])/)) {
|
||||
expr('dyn.' + v + ' = stack.pop()');
|
||||
expr('dyn.' + ch + ' = stack.pop()');
|
||||
continue;
|
||||
}
|
||||
|
||||
// %g[a-z]
|
||||
// get dynamic variable [a-z] and push it
|
||||
if (read(/^%g([a-z])/)) {
|
||||
expr('(stack.push(dyn.' + v + '), dyn.' + v + ')');
|
||||
expr('(stack.push(dyn.' + ch + '), dyn.' + ch + ')');
|
||||
continue;
|
||||
}
|
||||
|
||||
// %P[A-Z]
|
||||
// set static variable [a-z] to pop()
|
||||
if (read(/^%P([A-Z])/)) {
|
||||
expr('stat.' + v + ' = stack.pop()');
|
||||
expr('stat.' + ch + ' = stack.pop()');
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -851,7 +841,7 @@ Tput.prototype._compile = function(str, key, info) {
|
||||
// documented in other implementations. Relying on it will adversely
|
||||
// impact portability to other implementations.
|
||||
if (read(/^%g([A-Z])/)) {
|
||||
expr('(stack.push(v = stat.' + v + '), v)');
|
||||
expr('(stack.push(v = stat.' + ch + '), v)');
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -883,9 +873,9 @@ Tput.prototype._compile = function(str, key, info) {
|
||||
// %= %> %<
|
||||
// logical operations: push(pop() op pop())
|
||||
if (read(/^%([+\-*\/m&|\^=><])/)) {
|
||||
if (op === '=') op = '===';
|
||||
else if (op === 'm') op = '%';
|
||||
expr('(stack.push(v = (stack.pop() ' + op + ' stack.pop()) || 0), v)');
|
||||
if (ch === '=') ch = '===';
|
||||
else if (ch === 'm') ch = '%';
|
||||
expr('(stack.push(v = (stack.pop() ' + ch + ' stack.pop()) || 0), v)');
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -894,7 +884,7 @@ Tput.prototype._compile = function(str, key, info) {
|
||||
if (read(/^%([AO])/)) {
|
||||
// Are we supposed to store the result on the stack?
|
||||
expr('(stack.push(v = (stack.pop() '
|
||||
+ (op === 'A' ? '&&' : '||')
|
||||
+ (ch === 'A' ? '&&' : '||')
|
||||
+ ' stack.pop())), v)');
|
||||
continue;
|
||||
}
|
||||
@ -902,7 +892,7 @@ Tput.prototype._compile = function(str, key, info) {
|
||||
// %! %~
|
||||
// unary operations (logical and bit complement): push(op pop())
|
||||
if (read(/^%([!~])/)) {
|
||||
expr('(stack.push(v = ' + op + 'stack.pop()), v)');
|
||||
expr('(stack.push(v = ' + ch + 'stack.pop()), v)');
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -926,10 +916,6 @@ Tput.prototype._compile = function(str, key, info) {
|
||||
// It is possible to form else-if's a la Algol 68:
|
||||
// %? c1 %t b1 %e c2 %t b2 %e c3 %t b3 %e c4 %t b4 %e %;
|
||||
// where ci are conditions, bi are bodies.
|
||||
// Use the -f option of tic or infocmp to see the structure of
|
||||
// if-then-else's. Some strings, e.g., sgr can be very complicated when
|
||||
// written on one line. The -f option splits the string into lines with
|
||||
// the parts indented.
|
||||
if (read(/^%\?/)) {
|
||||
end = -1;
|
||||
stmt(';if (');
|
||||
@ -949,7 +935,6 @@ Tput.prototype._compile = function(str, key, info) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// if/then/else/end
|
||||
// Terminfo does elseif's like
|
||||
// this: %?[expr]%t...%e[expr]%t...%;
|
||||
if (read(/^%e/)) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user