diff --git a/lib/widget.js b/lib/widget.js index e0d79d3..84eded7 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -720,7 +720,7 @@ Screen.prototype.focus = function(offset) { var shown = this.input.filter(function(el) { return el.visible; }); - if (!shown || !offset) return; + if (!shown.length || !offset) return; var i = this.input.indexOf(this.focused); if (!~i) return; if (offset > 0) { @@ -804,6 +804,15 @@ Screen.prototype.key = function(key, listener) { return this.on('key ' + key, listener); }; +Screen.prototype.onceKey = function(key, listener) { + return this.once('key ' + key, listener); +}; + +Screen.prototype.unkey = +Screen.prototype.removeKey = function(key, listener) { + return this.removeListener('key ' + key, listener); +}; + Screen.prototype.spawn = function(file, args, options) { if (!Array.isArray(args)) { options = args; @@ -893,7 +902,9 @@ Screen.prototype.readEditor = function(options, callback) { var self = this , fs = require('fs') , editor = options.editor || process.env.EDITOR || 'vi' - , file = '/tmp/blessed.' + Math.random().toString(36) + , name = options.name || process.title || 'blessed' + , rnd = Math.random().toString(36).split('.').pop() + , file = '/tmp/' + name + '.' + rnd , args = [file] , opt; @@ -1040,9 +1051,9 @@ function Element(options) { this.on('mouseover', function() { Object.keys(effects).forEach(function(key) { var val = effects[key]; - if (self._htemp[key] == null) { - self._htemp[key] = self[key]; - } + //if (self._htemp[key] == null) { + self._htemp[key] = self[key]; + //} self[key] = val; }); self.screen.render(); @@ -1605,6 +1616,9 @@ Box.prototype.render = function(stop) { } } + // TODO: + // Calculate whether we moved/resized by checking the previous _lastPos. + // Maybe clear based on that. Possibly emit events here. ret = this._lastPos = { xi: xi_, xl: xl, @@ -1857,19 +1871,23 @@ Box.prototype.insertBottom = function(line) { }; Box.prototype.deleteTop = function() { + var reset = true; if (this._lastPos && this._lastPos.xi === 0 && this._lastPos.xl === this.screen.width) { this.screen.deleteTop(this._lastPos.yi, this._lastPos.yl - 1); + reset = false; } this._clines.splice((this.childBase || 0) + (this.border ? 1 : 0), 1); - this.setContent(this._clines.join('\n'), true); + this.setContent(this._clines.join('\n'), reset); }; Box.prototype.deleteBottom = function() { + var reset = true; if (this._lastPos && this._lastPos.xi === 0 && this._lastPos.xl === this.screen.width) { this.screen.deleteBottom(this._lastPos.yi, this._lastPos.yl - 1); + reset = false; } this._clines.splice((this.childBase || 0) + this.height - (this.border ? 2 : 0), 1); - this.setContent(this._clines.join('\n'), true); + this.setContent(this._clines.join('\n'), reset); }; /** @@ -2405,11 +2423,6 @@ Textbox.prototype.readInput = Textbox.prototype.setInput = function(callback) { var self = this; - if (this._timeout != null) { - clearTimeout(this._timeout); - delete this._timeout; - } - this.focus(); this.screen.grabKeys = true; @@ -2425,10 +2438,7 @@ Textbox.prototype.setInput = function(callback) { this._callback = function(err, value) { // self.screen.program.restoreCursor(); self.screen.program.hideCursor(); - // Wait for global keypress event to fire. - self._timeout = setTimeout(function() { - self.screen.grabKeys = false; - }, 1); + self.screen.grabKeys = false; //self.screen.focusPop(); //var el = self.screen.focusPop(); @@ -2586,11 +2596,6 @@ Textarea.prototype.readInput = Textarea.prototype.setInput = function(callback) { var self = this; - if (this._timeout != null) { - clearTimeout(this._timeout); - delete this._timeout; - } - this.focus(); this.screen.grabKeys = true; @@ -2601,9 +2606,7 @@ Textarea.prototype.setInput = function(callback) { this._callback = function(err, value) { self.screen.program.hideCursor(); - self._timeout = setTimeout(function() { - self.screen.grabKeys = false; - }, 1); + self.screen.grabKeys = false; return err ? callback(err) : callback(null, value);