2014-10-23 05:41:00 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var TextView = require('./text_view.js').TextView;
|
|
|
|
var miscUtil = require('./misc_util.js');
|
|
|
|
var strUtil = require('./string_util.js');
|
|
|
|
var util = require('util');
|
|
|
|
var assert = require('assert');
|
|
|
|
|
|
|
|
exports.EditTextView = EditTextView;
|
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
function EditTextView(options) {
|
2015-04-08 05:15:34 +00:00
|
|
|
options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
|
|
|
|
options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, true);
|
2014-10-23 05:41:00 +00:00
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
TextView.call(this, options);
|
2015-04-08 05:15:34 +00:00
|
|
|
|
2014-10-23 05:41:00 +00:00
|
|
|
this.clientBackspace = function() {
|
2014-11-03 23:49:15 +00:00
|
|
|
this.client.term.write(
|
|
|
|
'\b' + this.getANSIColor(this.getColor()) + this.fillChar + '\b' + this.getANSIColor(this.getFocusColor()));
|
2014-10-23 05:41:00 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
util.inherits(EditTextView, TextView);
|
|
|
|
|
2014-10-24 04:18:38 +00:00
|
|
|
EditTextView.prototype.onKeyPress = function(key, isSpecial) {
|
2014-10-23 05:41:00 +00:00
|
|
|
if(isSpecial) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(1 === key.length);
|
|
|
|
|
2014-11-03 23:49:15 +00:00
|
|
|
// :TODO: how to handle justify left/center?
|
2014-10-26 03:35:42 +00:00
|
|
|
|
2015-04-09 04:54:13 +00:00
|
|
|
if(this.text.length < this.maxLength) {
|
2014-10-23 05:41:00 +00:00
|
|
|
key = strUtil.stylizeString(key, this.textStyle);
|
|
|
|
|
|
|
|
this.text += key;
|
|
|
|
|
|
|
|
if(this.textMaskChar) {
|
|
|
|
this.client.term.write(this.textMaskChar);
|
|
|
|
} else {
|
|
|
|
this.client.term.write(key);
|
|
|
|
}
|
|
|
|
}
|
2014-10-24 04:18:38 +00:00
|
|
|
|
|
|
|
EditTextView.super_.prototype.onKeyPress.call(this, key, isSpecial);
|
2014-10-23 05:41:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
EditTextView.prototype.onSpecialKeyPress = function(keyName) {
|
2014-10-24 04:18:38 +00:00
|
|
|
// :TODO: handle 'enter' & others for multiLine
|
2014-10-23 05:41:00 +00:00
|
|
|
|
|
|
|
if(this.isSpecialKeyMapped('backspace', keyName)) {
|
|
|
|
if(this.text.length > 0) {
|
|
|
|
this.text = this.text.substr(0, this.text.length - 1);
|
|
|
|
this.clientBackspace();
|
|
|
|
}
|
|
|
|
}
|
2014-10-24 04:18:38 +00:00
|
|
|
|
|
|
|
EditTextView.super_.prototype.onSpecialKeyPress.call(this, keyName);
|
2014-10-23 05:41:00 +00:00
|
|
|
};
|