mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-22 18:56:00 +02:00
* Lots of code cleanup
* New standard MCI codes for labels * WIP MaskEditTextView * Extra styles for EditTextView
This commit is contained in:
parent
1a1dd53ca1
commit
a96af34a20
12 changed files with 150 additions and 62 deletions
|
@ -7,29 +7,54 @@ var miscUtil = require('./misc_util.js');
|
|||
var util = require('util');
|
||||
var assert = require('assert');
|
||||
|
||||
function MaskEditTextView(client, options) {
|
||||
exports.MaskEditTextView = MaskEditTextView;
|
||||
|
||||
// ##/##/#### <--styleSGR2 if fillChar
|
||||
// ^- styleSGR1
|
||||
// buildPattern -> [ RE, RE, '/', RE, RE, '/', RE, RE, RE, RE ]
|
||||
// patternIndex -----^
|
||||
|
||||
function MaskEditTextView(options) {
|
||||
options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
|
||||
options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, true);
|
||||
options.cursorStyle = miscUtil.valueWithDefault(options.cursorStyle, 'steady block');
|
||||
options.resizable = false;
|
||||
|
||||
TextView.call(this, client, options);
|
||||
TextView.call(this, options);
|
||||
|
||||
this.cursorPos = { x : 0 };
|
||||
|
||||
var self = this;
|
||||
|
||||
this.mask = options.mask || '';
|
||||
this.maskPattern = options.maskPattern || '';
|
||||
|
||||
this.buildPattern = function(pattern) {
|
||||
this.patternArray = [];
|
||||
for(var i = 0; i < pattern.length; i++) {
|
||||
if(pattern[i] in MaskEditTextView.maskPatternCharacterRegEx) {
|
||||
this.patternArray.push(MaskEditTextView.maskPatternCharacterRegEx[pattern[i]]);
|
||||
} else {
|
||||
this.patternArray.push(pattern[i]);
|
||||
}
|
||||
}
|
||||
console.log(this.patternArray)
|
||||
};
|
||||
|
||||
this.buildPattern(this.maskPattern);
|
||||
|
||||
}
|
||||
|
||||
util.inherits(MaskEditTextView, TextView);
|
||||
|
||||
MaskEditTextView.MaskCharacterRegEx = {
|
||||
MaskEditTextView.maskPatternCharacterRegEx = {
|
||||
'#' : /[0-9]/,
|
||||
'?' : /[a-zA-Z]/,
|
||||
'&' : /[\w\d\s]/, // 32-126, 128-255
|
||||
'A' : /[0-9a-zA-Z]/,
|
||||
};
|
||||
|
||||
MaskEditTextView.prototype.setMask = function(mask) {
|
||||
this.mask = mask;
|
||||
MaskEditTextView.prototype.setMaskPattern = function(pattern) {
|
||||
this.buildPattern(pattern);
|
||||
};
|
||||
|
||||
MaskEditTextView.prototype.onKeyPress = function(key, isSpecial) {
|
||||
|
@ -39,6 +64,25 @@ MaskEditTextView.prototype.onKeyPress = function(key, isSpecial) {
|
|||
|
||||
assert(1 === key.length);
|
||||
|
||||
if(this.text.length < this.maxLength) {
|
||||
key = strUtil.stylizeString(key, this.textStyle);
|
||||
|
||||
/*this.text += key;
|
||||
|
||||
if(this.text.length > this.dimens.width) {
|
||||
// no shortcuts - redraw the view
|
||||
this.redraw();
|
||||
} else {
|
||||
this.cursorPos.x += 1;
|
||||
|
||||
if(this.maskPatternChar) {
|
||||
this.client.term.write(this.maskPatternChar);
|
||||
} else {
|
||||
this.client.term.write(key);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
MaskEditTextView.super_.prototype.onKeyPress(this, key, isSpecial);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue