From c73a6c47b922b2c55615079eec1e7be09556b6d5 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 1 Jan 2014 22:42:38 -0600 Subject: [PATCH] expose screen.enter and screen.leave. fixes #29. --- lib/widget.js | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 4b93ae9..9f0e37b 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -348,26 +348,12 @@ function Screen(options) { self.emit('blur'); }); - this.program.alternateBuffer(); - this.program.hideCursor(); - this.program.cup(0, 0); - //this.program.csr(0, this.height - 1); - this.alloc(); + this.enter(); function reset() { if (reset.done) return; reset.done = true; - if (self.program.scrollTop !== 0 - || self.program.scrollBottom !== self.rows - 1) { - self.program.csr(0, self.height - 1); - } - self.program.clear(); - self.program.showCursor(); - self.program.normalBuffer(); - if (self._listenedMouse) { - self.program.disableMouse(); - } - self.program.flush(); + self.leave(); } this._maxListeners = Infinity; @@ -412,6 +398,31 @@ Screen.prototype.__proto__ = Node.prototype; Screen.prototype.type = 'screen'; +Screen.prototype.enter = function() { + if (this.program.isAlt) return; + this.program.alternateBuffer(); + this.program.hideCursor(); + this.program.cup(0, 0); + //this.program.csr(0, this.height - 1); + this.alloc(); +}; + +Screen.prototype.leave = function() { + if (!this.program.isAlt) return; + if (this.program.scrollTop !== 0 + || this.program.scrollBottom !== this.rows - 1) { + this.program.csr(0, this.height - 1); + } + // this.program.clear(); + this.alloc(); + this.program.showCursor(); + this.program.normalBuffer(); + if (this._listenedMouse) { + this.program.disableMouse(); + } + this.program.flush(); +}; + Screen.prototype.log = function() { return this.program.log.apply(this.program, arguments); };