From f026de2e5260119d24a62730391c4a1e71e9020c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 22 Jul 2015 04:51:54 -0700 Subject: [PATCH] make _twrite() wait for the first bytes to be output. --- lib/program.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/program.js b/lib/program.js index ae97fd3..51046b0 100644 --- a/lib/program.js +++ b/lib/program.js @@ -1559,6 +1559,8 @@ Program.prototype._buffer = function(text) { this._buf = text; nextTick(this._flush); + + return true; }; Program.prototype.flush = function(text) { @@ -1578,16 +1580,33 @@ Program.prototype._write = function(text) { // Example: `DCS tmux; ESC Pt ST` // Real: `DCS tmux; ESC Pt ESC \` Program.prototype._twrite = function(data) { + var self = this; + if (this.tmux) { // Replace all STs with BELs so they can be nested within the DCS code. data = data.replace(/\x1b\\/g, '\x07'); + // Wrap in tmux forward DCS: data = '\x1bPtmux;\x1b' + data + '\x1b\\'; + + // If we've never even flushed yet, it means we're still in + // the normal buffer. Wait for alt screen buffer. + if (this.output.bytesWritten === 0) { + nextTick(function() { + self.flush(); + self.output.write(data); + }); + return true; + } + // NOTE: Flushing the buffer is required in some cases. + // The DCS code must be at the start of the output. this.flush(); + // Write out raw now that the buffer is flushed. return this.output.write(data); } + return this._write(data); };