optimize alloc+clear. add a output dump option.

This commit is contained in:
Christopher Jeffrey 2013-07-14 12:08:03 -05:00
parent c9c01e0805
commit caa21ee356
2 changed files with 20 additions and 3 deletions

View File

@ -39,6 +39,10 @@ function Program(options) {
this.input = options.input || process.stdin;
this.output = options.output || process.stdout;
if (options.dump) {
this.dump(options.dump);
}
this.zero = options.zero !== false;
this.x = 0;
@ -77,6 +81,19 @@ function Program(options) {
Program.prototype.__proto__ = EventEmitter.prototype;
Program.prototype.dump =
Program.prototype.log = function(file) {
var self = this
, _write = this.output.write;
this.logger = require('fs').createWriteStream(file);
this.output.write = function(data) {
self.logger.write(data);
return _write.apply(this, arguments);
};
};
Program.prototype.setupTput = function() {
var self = this
, options = this.options

View File

@ -279,8 +279,6 @@ function Screen(options) {
this._ci = -1;
this.alloc();
function resize() {
self.alloc();
self.render();
@ -317,6 +315,7 @@ function Screen(options) {
this.program.alternateBuffer();
this.program.hideCursor();
this.alloc();
function reset() {
if (reset.done) return;
@ -535,6 +534,7 @@ Screen.prototype.__defineGetter__('height', function() {
});
Screen.prototype.alloc = function() {
this.program.clear();
var x, y;
this.lines = [];
for (y = 0; y < this.rows; y++) {
@ -548,7 +548,7 @@ Screen.prototype.alloc = function() {
for (y = 0; y < this.rows; y++) {
this.olines[y] = [];
for (x = 0; x < this.cols; x++) {
this.olines[y][x] = [];
this.olines[y][x] = [this.dattr, ' '];
}
}
};