cleanup old textbox code.

This commit is contained in:
Christopher Jeffrey 2013-06-09 14:34:13 -05:00
parent b29dddc547
commit 87aef67274
1 changed files with 5 additions and 73 deletions

View File

@ -1355,7 +1355,9 @@ Textbox.prototype.setInput = function(callback) {
this.focus(); this.focus();
// this.screen.program.saveCursor(); // 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.cup(
this.top + 1 + (this.border ? 1 : 0),
this.left + 1 + (this.border ? 1 : 0));
this.screen.program.showCursor(); this.screen.program.showCursor();
this.screen.program.sgr('normal'); this.screen.program.sgr('normal');
@ -1375,85 +1377,18 @@ Textbox.prototype.setInput = function(callback) {
this.on('keypress', this.__listener); 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) { Textbox.prototype._listener = function(ch, key) {
var callback = this._callback var callback = this._callback
, value = this.content; , value = this.content;
//var y = this.top + 1 + (this.border ? 1 : 0)
// , line = this.screen.lines[y];
if (key.name === 'escape' || key.name === 'enter') { if (key.name === 'escape' || key.name === 'enter') {
delete this._callback; delete this._callback;
//this.content = '';
this.setContent(''); this.setContent('');
this.removeListener('keypress', this.__listener); this.removeListener('keypress', this.__listener);
delete this.__listener; delete this.__listener;
callback(null, key.name === 'enter' ? value : null); callback(null, key.name === 'enter' ? value : null);
} else if (key.name === 'backspace') { } else if (key.name === 'backspace') {
if (this.content.length) { if (this.content.length) {
//this.content = this.content.slice(0, -1);
this.setContent(this.content.slice(0, -1)); this.setContent(this.content.slice(0, -1));
if (this.content.length < this.width - (this.border ? 2 : 0) - 1) { if (this.content.length < this.width - (this.border ? 2 : 0) - 1) {
this.screen.program.cub(); this.screen.program.cub();
@ -1461,7 +1396,6 @@ Textbox.prototype._listener = function(ch, key) {
} }
} else { } else {
if (ch) { if (ch) {
//this.content += ch;
this.setContent(this.content + ch); this.setContent(this.content + ch);
if (this.content.length < this.width - (this.border ? 2 : 0)) { if (this.content.length < this.width - (this.border ? 2 : 0)) {
this.screen.program.cuf(); this.screen.program.cuf();
@ -1469,8 +1403,6 @@ Textbox.prototype._listener = function(ch, key) {
} }
} }
//line.dirty = true;
this.screen.render(); this.screen.render();
}; };