stop using termcap aliases.

This commit is contained in:
Christopher Jeffrey 2013-08-29 21:55:36 -05:00
parent b5026af628
commit 353794224c
1 changed files with 29 additions and 78 deletions

View File

@ -656,16 +656,14 @@ Tput.prototype.compile = function(info) {
}); });
Object.keys(info.methods).forEach(function(key) { Object.keys(info.methods).forEach(function(key) {
var alias = Tput.alias[key]; if (!Tput.alias[key]) return;
if (!alias) return; Tput.alias[key].forEach(function(alias) {
if (!Array.isArray(alias)) alias = [alias];
alias.forEach(function(alias) {
if (info.methods[alias] && alias !== key && alias !== 'ML') {
// We can ignore `lines` and `ML` here.
throw new Error('Alias collision: ' + key + ' -> ' + alias);
}
info.methods[alias] = info.methods[key]; info.methods[alias] = info.methods[key];
}); });
// Could just use:
// Object.keys(Tput.aliasMap).forEach(function(key) {
// info.methods[key] = info.methods[Tput.aliasMap[key]];
// });
}); });
return info; return info;
@ -1435,19 +1433,12 @@ Tput.prototype.translateTermcap = function(info) {
}); });
// Separate aliases for termcap // Separate aliases for termcap
var talias = (function() { var map = (function() {
var alias = Tput.alias var out = {};
, out = {};
Object.keys(alias).forEach(function(key) { Object.keys(Tput.alias).forEach(function(key) {
var a = alias[key] var aliases = Tput.alias[key];
, n = a.slice(); out[aliases.termcap] = key;
if (!a._termcapRemoved) {
n.splice(1, 1);
}
out[a.termcap] = [key].concat(n);
}); });
return out; return out;
@ -1461,8 +1452,8 @@ Tput.prototype.translateTermcap = function(info) {
if (key === 'strings') { if (key === 'strings') {
info.strings[cap] = self._captoinfo(cap, info.strings[cap], 1); info.strings[cap] = self._captoinfo(cap, info.strings[cap], 1);
} }
if (talias[cap]) { if (map[cap]) {
out[key][talias[cap][0]] = info[key][cap]; out[key][map[cap]] = info[key][cap];
} else { } else {
// NOTE: Possibly include all termcap names // NOTE: Possibly include all termcap names
// in a separate alias.js file. Some are // in a separate alias.js file. Some are
@ -2274,62 +2265,25 @@ function sprintf(src) {
* Aliases * Aliases
*/ */
Tput.alias = require('./alias'); Tput._alias = require('./alias');
Tput.alias = {};
['bools', 'numbers', 'strings'].forEach(function(type) {
Object.keys(Tput._alias[type]).forEach(function(key) {
var aliases = Tput._alias[type][key];
Tput.alias[key] = [aliases[0]];
Tput.alias[key].terminfo = aliases[0];
Tput.alias[key].termcap = aliases[1];
});
});
// Bools // Bools
Tput.alias.bools.no_esc_ctlc.push('beehive_glitch'); Tput.alias.no_esc_ctlc.push('beehive_glitch');
Tput.alias.bools.dest_tabs_magic_smso.push('teleray_glitch'); Tput.alias.dest_tabs_magic_smso.push('teleray_glitch');
// Numbers // Numbers
Tput.alias.numbers.micro_col_size.push('micro_char_size'); Tput.alias.micro_col_size.push('micro_char_size');
// Merge into one object
merge(Tput.alias, Tput.alias.bools);
delete Tput.alias.bools;
merge(Tput.alias, Tput.alias.numbers);
delete Tput.alias.numbers;
merge(Tput.alias, Tput.alias.strings);
delete Tput.alias.strings;
// Make sure there are no collisions between terminfo names
// and termcap names. Terminfo takes precedence.
Tput._vec = Object.keys(Tput.alias).map(function(key) {
return Array.isArray(Tput.alias[key])
? Tput.alias[key][0]
: Tput.alias[key];
});
Object.keys(Tput.alias).forEach(function(key) {
if (!Array.isArray(Tput.alias[key])) {
return;
}
var alias = Tput.alias[key]
, tcap = alias[1];
alias.name = key;
alias.terminfo = alias[0];
alias.termcap = alias[1];
if (!tcap) return;
if (~Tput._vec.indexOf(tcap)) {
alias._termcapRemoved = true;
alias.splice(1, 1);
}
});
assert.notEqual(Tput.alias.exit_delete_mode[1], 'ed');
assert.equal(Tput.alias.exit_delete_mode.termcap, 'ed');
// assert.notEqual(Tput.alias.lines[0], 'lines');
// assert.notEqual(Tput.alias.set_lr_margin[1], 'ML');
// Possibly just ignore certain aliases like so:
// Tput.alias.exit_delete_mode.ignore = 1;
// Tput.alias.lines.ignore = 0;
// Tput.alias.set_lr_margin.ignore = 1;
/** /**
* Feature Checking * Feature Checking
@ -2338,11 +2292,8 @@ assert.equal(Tput.alias.exit_delete_mode.termcap, 'ed');
Tput.aliasMap = {}; Tput.aliasMap = {};
Object.keys(Tput.alias).forEach(function(key) { Object.keys(Tput.alias).forEach(function(key) {
var aliases = Array.isArray(Tput.alias[key])
? Tput.alias[key]
: [Tput.alias[key]];
Tput.aliasMap[key] = key; Tput.aliasMap[key] = key;
aliases.forEach(function(k) { Tput.alias[key].forEach(function(k) {
Tput.aliasMap[k] = key; Tput.aliasMap[k] = key;
}); });
}); });