From caa21ee356c27ecf565d149f9cc28b39b37147d8 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 14 Jul 2013 12:08:03 -0500 Subject: [PATCH] optimize alloc+clear. add a output dump option. --- lib/program.js | 17 +++++++++++++++++ lib/widget.js | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/program.js b/lib/program.js index 79d36d7..25c55cc 100644 --- a/lib/program.js +++ b/lib/program.js @@ -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 diff --git a/lib/widget.js b/lib/widget.js index 8f93298..a7160ea 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -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, ' ']; } } };