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; }