refactor. misc fixes.

This commit is contained in:
Christopher Jeffrey 2013-02-25 19:10:19 -06:00
parent 618ba14369
commit 44ca13c291
2 changed files with 60 additions and 34 deletions

View File

@ -44,28 +44,7 @@ function Program(options) {
this.terminal = process.env.TERM || 'xterm';
if (options.tput) {
this.tput = new Tput({
term: this.terminal,
extended: options.extended || false,
printf: options.printf || false
});
this.put = function() {
var args = Array.prototype.slice.call(arguments)
, cap = args.shift();
if (!this.tput[cap]) return;
return this.write(this.tput[cap].apply(this.tput, args));
};
Object.keys(this.tput).forEach(function(key) {
if (typeof self.tput[key] !== 'function') {
self.put[key] = self.tput[key];
return;
}
self.put[key] = function() {
return self.write(self.tput[key].apply(self.tput, arguments));
};
});
this.setupTput();
}
this.listen();
@ -75,6 +54,45 @@ function Program(options) {
Program.prototype.__proto__ = EventEmitter.prototype;
Program.prototype.setupTput = function(is) {
var self = this
, options = this.options;
var write = this.write.bind(this);
var tput = this.tput = new Tput({
term: this.terminal,
extended: options.extended || false,
printf: options.printf || false,
padding: options.padding || false
});
this.put = function() {
var args = Array.prototype.slice.call(arguments)
, cap = args.shift();
if (tput[cap]) {
return this.write(tput[cap].apply(tput, args));
}
};
Object.keys(tput).forEach(function(key) {
if (typeof tput[key] !== 'function') {
self.put[key] = tput[key];
return;
}
if (options.padding) {
self.put[key] = function() {
return tput._print(tput[key].apply(tput, arguments), write);
};
} else {
self.put[key] = function() {
return self.write(tput[key].apply(tput, arguments));
};
}
});
};
Program.prototype.term = function(is) {
return this.terminal.indexOf(is) === 0;
};

View File

@ -174,11 +174,12 @@ Tput.prototype.parseTerminfo = function(data) {
if (this.extended) {
i += h.strTableSize;
l = data.length;
if (i < l) {
if (i < l - 1) {
var extended = this.parseExtended(data.slice(i));
['bools', 'numbers', 'strings'].forEach(function(key) {
merge(info[key], extended[key]);
});
// info.extendedHexer = extended.header;
}
}
@ -445,7 +446,7 @@ Tput.prototype._compile = function(val) {
case 'string':
break;
default:
return function() {};
return noop;
}
if (!val) {
@ -566,7 +567,7 @@ Tput.prototype._compile = function(val) {
ch = '\\n';
break;
case 'l':
ch = '';
ch = '\\x85';
break;
case 'r':
ch = '\\r';
@ -1094,7 +1095,7 @@ function sprintf(src) {
// Should return here?
param = isFinite(param)
? String.fromCharCode(param)
: param[0];
: '';
break;
}
@ -1165,15 +1166,20 @@ function sprintf(src) {
Tput.alias = require('./alias');
// Bools
merge(Tput.alias.bools, {
'no_esc_ctlc': 'beehive_glitch',
'dest_tabs_magic_smso': 'teleray_glitch',
});
Tput.alias.bools.no_esc_ctlc.push('beehive_glitch');
Tput.alias.bools.dest_tabs_magic_smso.push('teleray_glitch');
// merge(Tput.alias.bools, {
// 'no_esc_ctlc': 'beehive_glitch',
// 'dest_tabs_magic_smso': 'teleray_glitch',
// });
// Numbers
merge(Tput.alias.numbers, {
'micro_col_size': 'micro_char_size'
});
Tput.alias.numbers.micro_col_size.push('micro_char_size');
// merge(Tput.alias.numbers, {
// 'micro_col_size': 'micro_char_size'
// });
// Merge into one object
merge(Tput.alias, Tput.alias.bools);
@ -1207,7 +1213,9 @@ Object.keys(Tput.alias).forEach(function(key) {
}
});
assert.equal(Tput.alias.exit_delete_mode[1], undefined);
assert.notEqual(Tput.alias.exit_delete_mode[1], 'ed');
// assert.notEqual(Tput.alias.lines[0], 'lines');
// assert.notEqual(Tput.alias.set_lr_margin[1], 'ML');
/**
* Terminfo Data