diff --git a/lib/widget.js b/lib/widget.js index 2329c0c..3e28e6d 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -142,6 +142,10 @@ function Screen(options) { bottom: this.bottom = 0 }; + this.focused = null; + this.clickable = []; + this.input = []; + this.alloc(); this.program.on('resize', function() { @@ -150,9 +154,14 @@ function Screen(options) { self.emit('resize'); }); - this.focused = null; - this.clickable = []; - this.input = []; + this.program.alternateBuffer(); + this.program.hideCursor(); + + process.on('exit', function() { + self.program.clear(); + self.program.showCursor(); + self.program.normalBuffer(); + }); } Screen._default = null; @@ -282,7 +291,6 @@ Screen.prototype.draw = function(start, end) { , o; this.program.saveCursor(); - //this.program.write('\x1b[1;1H'); for (y = start; y <= end; y++) { line = this.lines[y]; @@ -1190,7 +1198,7 @@ ScrollableText.prototype.scroll = function(offset) { // and put it in a scrollable text box. if (this.content != null) { var cb = this.childBase - , data = this.render(true) + , data = this.render(true) || 0 , xi = data.xi , xl = data.xl , xxl = xl - (this.border ? 1 : 0) @@ -1199,6 +1207,9 @@ ScrollableText.prototype.scroll = function(offset) { , xxxi , cci; + // XXX Temporary workaround for .render() not working while hidden. + if (!data) return ret; + if (this.contentIndex != null) { ci = this.contentIndex; cb = diff; diff --git a/test/widget.js b/test/widget.js index c341450..3791231 100644 --- a/test/widget.js +++ b/test/widget.js @@ -1,11 +1,7 @@ var blessed = require('blessed') - , program = blessed() - , screen; + , program = blessed(); -program.alternateBuffer(); -program.hideCursor(); - -screen = new blessed.Screen({ +var screen = new blessed.Screen({ program: program }); @@ -186,10 +182,6 @@ program.on('keypress', function(ch, key) { : screen.focusNext(); } if (key.name === 'escape' || key.name === 'q') { - program.disableMouse(); - program.clear(); - program.showCursor(); - program.normalBuffer(); return process.exit(0); } }); @@ -199,8 +191,8 @@ list.focus(); screen.render(); setInterval(function() { - //stext.toggle(); - //screen.render(); + stext.toggle(); + screen.render(); }, 1000); (function fill() {