From 797feb6ab12c1e1566ec7f74ac69bf68de64c021 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 21 Jul 2015 20:11:20 -0700 Subject: [PATCH] refactor listen. --- lib/program.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/program.js b/lib/program.js index 8a65a1c..c5f4249 100644 --- a/lib/program.js +++ b/lib/program.js @@ -313,17 +313,23 @@ Program.prototype.listen = function() { // self._originalTitle = data.text; // }); - this._listenInput(); - this._listenOutput(); + // Listen for keys/mouse on input + if (!this.input._blessedListened) { + this.input._blessedListened = true; + this._listenInput(); + } + + // Listen for resize on output + if (!this.output._blessedListened) { + this.output._blessedListened = true; + this._listenOutput(); + } }; Program.prototype._listenInput = function() { var keys = require('./keys') , self = this; - if (this.input._blessedListened) return; - this.input._blessedListened = true; - // Input this.input.on('keypress', function(ch, key) { key = key || { ch: ch }; @@ -385,9 +391,6 @@ Program.prototype._listenInput = function() { Program.prototype._listenOutput = function() { var self = this; - if (this.output._blessedListened) return; - this.output._blessedListened = true; - if (!this.output.isTTY) { nextTick(function() { self.emit('warning', 'Output is not a TTY');