termcap compilation

This commit is contained in:
Christopher Jeffrey 2013-02-27 16:34:57 -06:00
parent 8a3f29fddb
commit f1fe73e974
1 changed files with 74 additions and 3 deletions

View File

@ -1032,11 +1032,67 @@ Tput.prototype.parseTermcap = function(data) {
* man termcap
*/
Tput.prototype.compileTermcap = function() {
Tput.prototype.compileTermcap = function(info) {
var self = this;
info.all = {};
['bools', 'numbers', 'strings'].forEach(function(key) {
Object.keys(info[key]).forEach(function(cap) {
info.all[cap] = self._compile(info[key][cap]);
});
});
Object.keys(Tput.alias).forEach(function(ti) {
var a = Tput.alias[ti]
, tia = a[0]
, tc = a.termcap || a[1];
if (info.all[tc]) {
if (!a.termcap) {
a = a.slice();
a.splice(1, 1);
}
info.all[ti] = info.all[tc];
a.forEach(function(k) {
info.all[k] = info.all[tc];
});
}
});
Object.keys(info.all).forEach(function(key) {
self[key] = info.all[key];
});
return info.all;
};
Tput.prototype._compileTermcap = function() {
};
/*Tput.prototype.compileTermcap = function(info) {
var self = this
, alias = Tput.talias;
info.all = {};
['bools', 'numbers', 'strings'].forEach(function(key) {
Object.keys(info[key]).forEach(function(cap) {
var val = self._compile(info[key][cap]);
info[key][cap] = val;
info.all[cap] = val;
if (alias[cap]) {
alias.forEach(function(k) {
info[key][k] = val;
info.all[k] = val;
});
}
});
});
Object.keys(info.all).forEach(function(key) {
self[key] = info.all[key];
});
return info.all;
};*/
/**
* Helpers
@ -1183,6 +1239,20 @@ delete Tput.alias.numbers;
merge(Tput.alias, Tput.alias.strings);
delete Tput.alias.strings;
// Separate aliases for termcap
/*Tput.talias = (function() {
var alias = Tput.alias
, out = {};
Object.keys(alias).forEach(function(key) {
var a = alias[key].slice()
, tc = a.splice(1, 1)[0];
out[tc] = [key].concat(a);
});
return out;
})();*/
// Make sure there are no collisions between cap and tcap.
Tput._vec = Object.keys(Tput.alias).map(function(key) {
return Array.isArray(Tput.alias[key])
@ -1201,6 +1271,7 @@ Object.keys(Tput.alias).forEach(function(key) {
if (!tcap) return;
if (~Tput._vec.indexOf(tcap)) {
alias.termcap = tcap;
alias.splice(1, 1);
}
});