From 797dcc2369a0ff15bc3a36c01d0489a1e4a3d721 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 22 Jul 2015 06:03:40 -0700 Subject: [PATCH] do not use nextTick to wait for flush. --- lib/program.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/program.js b/lib/program.js index 63bfad1..7feb3ab 100644 --- a/lib/program.js +++ b/lib/program.js @@ -1598,7 +1598,9 @@ 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; + var self = this + , iterations = 0 + , timer; if (this.tmux) { // Replace all STs with BELs so they can be nested within the DCS code. @@ -1610,10 +1612,13 @@ Program.prototype._twrite = function(data) { // 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); - }); + timer = setInterval(function() { + if (self.output.bytesWritten > 0 || ++iterations === 50) { + clearInterval(timer); + self.flush(); + self.output.write(data); + } + }, 100); return true; }