From 87aef67274c53ce9abef9c63524cb4371a4f2247 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 9 Jun 2013 14:34:13 -0500 Subject: [PATCH] cleanup old textbox code. --- lib/widget.js | 78 ++++----------------------------------------------- 1 file changed, 5 insertions(+), 73 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 8927d0c..48d79d6 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -1354,13 +1354,15 @@ Textbox.prototype.setInput = function(callback) { this.screen._grabKeys = true; this.focus(); - //this.screen.program.saveCursor(); - this.screen.program.cup(this.top + 1 + (this.border ? 1 : 0), this.left + 1 + (this.border ? 1 : 0)); + // this.screen.program.saveCursor(); + this.screen.program.cup( + this.top + 1 + (this.border ? 1 : 0), + this.left + 1 + (this.border ? 1 : 0)); this.screen.program.showCursor(); this.screen.program.sgr('normal'); this._callback = function(err, value) { - //self.screen.program.restoreCursor(); + // self.screen.program.restoreCursor(); self.screen.program.hideCursor(); // Wait for global keypress event to fire. process.nextTick(function() { @@ -1375,85 +1377,18 @@ Textbox.prototype.setInput = function(callback) { this.on('keypress', this.__listener); }; -Textbox.prototype._listenerFast = function(ch, key) { - var y = this.top + 1 + (this.border ? 1 : 0) - , x = this.left + 1 + (this.border ? 1 : 0) - , line = this.screen.lines[y] - , callback = this._callback - , value = this.value; - - if (key.name === 'escape' || key.name === 'enter') { - delete this._callback; - this.value = ''; - this.removeListener('keypress', this.__listener); - delete this.__listener; - this.screen.program.cup(y, x); - this.screen.program.write(Array(value.length + 1).join(' ')); - callback(null, key.name === 'enter' ? value : null); - } else if (key.name === 'backspace') { - if (this.value.length) { - this.value = this.value.slice(0, -1); - this.screen.program.cub(); - this.screen.program.write(' '); - this.screen.program.cub(); - } - } else { - if (ch) { - this.value += ch; - this.screen.program.write(ch); - } - } -}; - -Textbox.prototype._listenerStupid = function(ch, key) { - var y = this.top + 1 + (this.border ? 1 : 0) - , x = this.left + 1 + (this.border ? 1 : 0) - , line = this.screen.lines[y] - , callback = this._callback - , value = this.value; - - if (key.name === 'escape' || key.name === 'enter') { - delete this._callback; - this.value = ''; - this.removeListener('keypress', this.__listener); - delete this.__listener; - this.screen.clearRegion(x, x + value.length, y, y); - callback(null, key.name === 'enter' ? value : null); - } else if (key.name === 'backspace') { - if (this.value.length) { - line[x + this.value.length][1] = ' '; - line.dirty = true; - this.value = this.value.slice(0, -1); - } - } else { - if (ch) { - line[x + this.value.length][0] = this.screen.dattr; - line[x + this.value.length][1] = ch; - line.dirty = true; - this.value += ch; - } - } - - this.screen.render(); -}; - Textbox.prototype._listener = function(ch, key) { var callback = this._callback , value = this.content; - //var y = this.top + 1 + (this.border ? 1 : 0) - // , line = this.screen.lines[y]; - if (key.name === 'escape' || key.name === 'enter') { delete this._callback; - //this.content = ''; this.setContent(''); this.removeListener('keypress', this.__listener); delete this.__listener; callback(null, key.name === 'enter' ? value : null); } else if (key.name === 'backspace') { if (this.content.length) { - //this.content = this.content.slice(0, -1); this.setContent(this.content.slice(0, -1)); if (this.content.length < this.width - (this.border ? 2 : 0) - 1) { this.screen.program.cub(); @@ -1461,7 +1396,6 @@ Textbox.prototype._listener = function(ch, key) { } } else { if (ch) { - //this.content += ch; this.setContent(this.content + ch); if (this.content.length < this.width - (this.border ? 2 : 0)) { this.screen.program.cuf(); @@ -1469,8 +1403,6 @@ Textbox.prototype._listener = function(ch, key) { } } - //line.dirty = true; - this.screen.render(); };