From ee31799e7fbf6e5b24aa01dca49d1d29205bbd6b Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 5 Aug 2015 03:27:24 -0700 Subject: [PATCH] use _owrite instead of output.write. --- lib/program.js | 20 +++++++++++++------- lib/widgets/screen.js | 2 +- lib/widgets/terminal.js | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/program.js b/lib/program.js index 3a657c2..c10f85e 100644 --- a/lib/program.js +++ b/lib/program.js @@ -243,7 +243,7 @@ Program.prototype.setupTput = function() { var self = this , options = this.options - , write = this.write.bind(this); + , write = this._write.bind(this); var tput = this.tput = new Tput({ term: this.terminal, @@ -1596,10 +1596,16 @@ Program.prototype.response = function(name, text, callback, noBypass) { : this._twrite(text); }; +Program.prototype._owrite = +Program.prototype.write = function(text) { + if (!this.output.writable) return; + return this.output.write(text); +}; + Program.prototype._buffer = function(text) { if (this._exiting) { this.flush(); - this.output.write(text); + this._owrite(text); return; } @@ -1617,7 +1623,7 @@ Program.prototype._buffer = function(text) { Program.prototype.flush = function(text) { if (!this._buf) return; - this.output.write(this._buf); + this._owrite(this._buf); this._buf = ''; }; @@ -1626,7 +1632,7 @@ Program.prototype._write = function(text) { if (this.useBuffer) { return this._buffer(text); } - return this.output.write(text); + return this._owrite(text); }; // Example: `DCS tmux; ESC Pt ST` @@ -1650,7 +1656,7 @@ Program.prototype._twrite = function(data) { if (self.output.bytesWritten > 0 || ++iterations === 50) { clearInterval(timer); self.flush(); - self.output.write(data); + self._owrite(data); } }, 100); return true; @@ -1661,14 +1667,14 @@ Program.prototype._twrite = function(data) { this.flush(); // Write out raw now that the buffer is flushed. - return this.output.write(data); + return this._owrite(data); } return this._write(data); }; Program.prototype.echo = -Program.prototype.write = function(text, attr) { +Program.prototype.print = function(text, attr) { return attr ? this._write(this.text(text, attr)) : this._write(text); diff --git a/lib/widgets/screen.js b/lib/widgets/screen.js index 03c1814..ca2598c 100644 --- a/lib/widgets/screen.js +++ b/lib/widgets/screen.js @@ -1351,7 +1351,7 @@ Screen.prototype.draw = function(start, end) { } // this.program.flush(); - // this.program.output.write(pre + main + post); + // this.program._owrite(pre + main + post); this.program._write(pre + main + post); } diff --git a/lib/widgets/terminal.js b/lib/widgets/terminal.js index 90dc1cf..458daf1 100644 --- a/lib/widgets/terminal.js +++ b/lib/widgets/terminal.js @@ -194,7 +194,7 @@ Terminal.prototype.bootstrap = function() { this.term.on('passthrough', function(data) { self.screen.program.flush(); - self.screen.program.output.write(data); + self.screen.program._owrite(data); }); this.on('resize', function() {