* 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
26
core/bbs.js
26
core/bbs.js
|
@ -169,8 +169,6 @@ function startListening() {
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('end', function onClientEnd() {
|
client.on('end', function onClientEnd() {
|
||||||
logger.log.info({ clientId : client.runtime.id }, 'Client disconnected');
|
|
||||||
|
|
||||||
removeClient(client);
|
removeClient(client);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -192,7 +190,20 @@ function startListening() {
|
||||||
|
|
||||||
function addNewClient(client) {
|
function addNewClient(client) {
|
||||||
var id = client.runtime.id = clientConnections.push(client) - 1;
|
var id = client.runtime.id = clientConnections.push(client) - 1;
|
||||||
logger.log.debug('Connection count is now %d', clientConnections.length);
|
|
||||||
|
var connInfo = {
|
||||||
|
connectionCount : clientConnections.length,
|
||||||
|
clientId : client.runtime.id,
|
||||||
|
};
|
||||||
|
|
||||||
|
if(logger.log.debug()) {
|
||||||
|
connInfo.address = client.address();
|
||||||
|
} else {
|
||||||
|
connInfo.ip = client.address().address;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.log.info(connInfo, 'Client connected');
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +211,14 @@ function removeClient(client) {
|
||||||
var i = clientConnections.indexOf(client);
|
var i = clientConnections.indexOf(client);
|
||||||
if(i > -1) {
|
if(i > -1) {
|
||||||
clientConnections.splice(i, 1);
|
clientConnections.splice(i, 1);
|
||||||
logger.log.debug('Connection count is now %d', clientConnections.length);
|
|
||||||
|
logger.log.info(
|
||||||
|
{
|
||||||
|
connectionCount : clientConnections.length,
|
||||||
|
clientId : client.runtime.id
|
||||||
|
},
|
||||||
|
'Client disconnected'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ function getDefaultConfig() {
|
||||||
|
|
||||||
users : {
|
users : {
|
||||||
usernameMin : 2,
|
usernameMin : 2,
|
||||||
usernameMax : 22,
|
usernameMax : 16,
|
||||||
usernamePattern : '^[A-Za-z0-9~!@#$%^&*()\\-\\_+]+$',
|
usernamePattern : '^[A-Za-z0-9~!@#$%^&*()\\-\\_+]+$',
|
||||||
passwordMin : 6,
|
passwordMin : 6,
|
||||||
passwordMax : 128,
|
passwordMax : 128,
|
||||||
|
|
|
@ -23,7 +23,8 @@ function EditTextView(options) {
|
||||||
this.cursorPos = { x : 0 };
|
this.cursorPos = { x : 0 };
|
||||||
|
|
||||||
this.clientBackspace = function() {
|
this.clientBackspace = function() {
|
||||||
this.client.term.write('\b' + this.getSGR() + this.fillChar + '\b' + this.getFocusSGR());
|
var fillCharSGR = this.getStyleSGR(1) || this.getSGR();
|
||||||
|
this.client.term.write('\b' + fillCharSGR + this.fillChar + '\b' + this.getFocusSGR());
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,29 +7,54 @@ var miscUtil = require('./misc_util.js');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var assert = require('assert');
|
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.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
|
||||||
options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, 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;
|
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);
|
util.inherits(MaskEditTextView, TextView);
|
||||||
|
|
||||||
MaskEditTextView.MaskCharacterRegEx = {
|
MaskEditTextView.maskPatternCharacterRegEx = {
|
||||||
'#' : /[0-9]/,
|
'#' : /[0-9]/,
|
||||||
'?' : /[a-zA-Z]/,
|
'?' : /[a-zA-Z]/,
|
||||||
'&' : /[\w\d\s]/, // 32-126, 128-255
|
'&' : /[\w\d\s]/, // 32-126, 128-255
|
||||||
'A' : /[0-9a-zA-Z]/,
|
'A' : /[0-9a-zA-Z]/,
|
||||||
};
|
};
|
||||||
|
|
||||||
MaskEditTextView.prototype.setMask = function(mask) {
|
MaskEditTextView.prototype.setMaskPattern = function(pattern) {
|
||||||
this.mask = mask;
|
this.buildPattern(pattern);
|
||||||
};
|
};
|
||||||
|
|
||||||
MaskEditTextView.prototype.onKeyPress = function(key, isSpecial) {
|
MaskEditTextView.prototype.onKeyPress = function(key, isSpecial) {
|
||||||
|
@ -39,6 +64,25 @@ MaskEditTextView.prototype.onKeyPress = function(key, isSpecial) {
|
||||||
|
|
||||||
assert(1 === key.length);
|
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);
|
MaskEditTextView.super_.prototype.onKeyPress(this, key, isSpecial);
|
||||||
|
|
|
@ -7,6 +7,7 @@ var ButtonView = require('./button_view.js').ButtonView;
|
||||||
var VerticalMenuView = require('./vertical_menu_view.js').VerticalMenuView;
|
var VerticalMenuView = require('./vertical_menu_view.js').VerticalMenuView;
|
||||||
var SpinnerMenuView = require('./spinner_menu_view.js').SpinnerMenuView;
|
var SpinnerMenuView = require('./spinner_menu_view.js').SpinnerMenuView;
|
||||||
var ToggleMenuView = require('./toggle_menu_view.js').ToggleMenuView;
|
var ToggleMenuView = require('./toggle_menu_view.js').ToggleMenuView;
|
||||||
|
var MaskEditTextView = require('./mask_edit_text_view.js').MaskEditTextView;
|
||||||
var Config = require('./config.js').config;
|
var Config = require('./config.js').config;
|
||||||
var ansi = require('./ansi_term.js');
|
var ansi = require('./ansi_term.js');
|
||||||
|
|
||||||
|
@ -23,32 +24,37 @@ function MCIViewFactory(client) {
|
||||||
}
|
}
|
||||||
|
|
||||||
MCIViewFactory.prototype.getPredefinedViewLabel = function(code) {
|
MCIViewFactory.prototype.getPredefinedViewLabel = function(code) {
|
||||||
var label;
|
|
||||||
switch(code) {
|
|
||||||
// :TODO: Fix conflict with ButtonView (BN); chagne to BT
|
|
||||||
case 'BN' : label = Config.general.boardName; break;
|
|
||||||
case 'VL' : label = 'ENiGMA½ v' + packageJson.version; break;
|
|
||||||
case 'VN' : label = packageJson.version; break;
|
|
||||||
|
|
||||||
case 'UN' : label = this.client.user.username; break;
|
return {
|
||||||
case 'UR' : label = this.client.user.properties.real_name; break;
|
BN : Config.general.boardName,
|
||||||
case 'LO' : label = this.client.user.properties.location; break;
|
VL : 'ENiGMA½ v' + packageJson.version,
|
||||||
|
VN : packageJson.version,
|
||||||
|
|
||||||
case 'OS' :
|
UN : this.client.user.username,
|
||||||
switch(os.platform()) {
|
UI : this.client.user.userId,
|
||||||
case 'linux' : label = 'Linux'; break;
|
UG : _.values(this.client.user.groups).join(', '),
|
||||||
case 'darwin' : label = 'OS X'; break;
|
UR : this.client.user.properties.real_name,
|
||||||
case 'win32' : label = 'Windows'; break;
|
LO : this.client.user.properties.location,
|
||||||
case 'sunos' : label = 'SunOS'; break;
|
UA : this.client.user.properties.age,
|
||||||
default : label = os.type(); break;
|
US : this.client.user.properties.sex,
|
||||||
}
|
UE : this.client.user.properties.email_address,
|
||||||
break;
|
UW : this.client.user.properties.web_address,
|
||||||
|
UF : this.client.user.properties.affiliation,
|
||||||
|
UT : this.client.user.properties.theme_id,
|
||||||
|
|
||||||
case 'OA' : label = os.arch(); break;
|
OS : {
|
||||||
case 'SC' : label = os.cpus()[0].model; break;
|
linux : 'Linux',
|
||||||
}
|
darwin : 'Mac OS X',
|
||||||
|
win32 : 'Windows',
|
||||||
|
sunos : 'SunOS',
|
||||||
|
freebsd : 'FreeBSD',
|
||||||
|
}[os.platform()] || os.type(),
|
||||||
|
|
||||||
return label;
|
OA : os.arch(),
|
||||||
|
SC : os.cpus()[0].model,
|
||||||
|
|
||||||
|
IP : this.client.address().address,
|
||||||
|
}[code];
|
||||||
};
|
};
|
||||||
|
|
||||||
MCIViewFactory.prototype.createFromMCI = function(mci) {
|
MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||||
|
@ -111,6 +117,14 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||||
view = new EditTextView(options);
|
view = new EditTextView(options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// Masked Edit Text
|
||||||
|
case 'ME' :
|
||||||
|
setOption(0, 'textStyle');
|
||||||
|
setFocusOption(0, 'focusTextStyle');
|
||||||
|
|
||||||
|
view = new MaskEditTextView(options);
|
||||||
|
break;
|
||||||
|
|
||||||
// Pre-defined Label (Text View)
|
// Pre-defined Label (Text View)
|
||||||
case 'PL' :
|
case 'PL' :
|
||||||
if(mci.args.length > 0) {
|
if(mci.args.length > 0) {
|
||||||
|
|
|
@ -80,7 +80,7 @@ function TextView(options) {
|
||||||
this.fillChar,
|
this.fillChar,
|
||||||
this.justify,
|
this.justify,
|
||||||
this.hasFocus ? this.getFocusSGR() : this.getSGR(),
|
this.hasFocus ? this.getFocusSGR() : this.getSGR(),
|
||||||
this.getSGR() // :TODO: use extended style color if avail
|
this.getStyleSGR(1) || this.getSGR()
|
||||||
));
|
));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -191,6 +191,11 @@ View.prototype.getSGR = function() {
|
||||||
return this.ansiSGR;
|
return this.ansiSGR;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
View.prototype.getStyleSGR = function(x) {
|
||||||
|
assert(_.isNumber(x));
|
||||||
|
return this['styleSGR' + x];
|
||||||
|
}
|
||||||
|
|
||||||
View.prototype.getFocusSGR = function() {
|
View.prototype.getFocusSGR = function() {
|
||||||
return this.ansiFocusSGR;
|
return this.ansiFocusSGR;
|
||||||
};
|
};
|
||||||
|
|
|
@ -190,6 +190,8 @@ function ViewController(options) {
|
||||||
setViewProp('justify');
|
setViewProp('justify');
|
||||||
setViewProp('textOverflow');
|
setViewProp('textOverflow');
|
||||||
|
|
||||||
|
setViewProp('maskPattern', function(v) { view.setMaskPattern(v); });
|
||||||
|
|
||||||
setViewProp('maxLength');
|
setViewProp('maxLength');
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -11,11 +11,6 @@
|
||||||
// @art:artName
|
// @art:artName
|
||||||
// @method:/methodName (local to module.js)
|
// @method:/methodName (local to module.js)
|
||||||
// ... pass isFocused/etc. into draw method
|
// ... pass isFocused/etc. into draw method
|
||||||
"draw" : {
|
|
||||||
"normal" : ...,
|
|
||||||
"focus" : ...
|
|
||||||
}
|
|
||||||
|
|
||||||
NOte that @draw & @art should check theme first.
|
NOte that @draw & @art should check theme first.
|
||||||
@draw:myMethod -> theme/draw.js::myMethod(opts)
|
@draw:myMethod -> theme/draw.js::myMethod(opts)
|
||||||
|
|
||||||
|
@ -57,7 +52,6 @@
|
||||||
"focus" : true,
|
"focus" : true,
|
||||||
// :TODO: need a good way to localize these ... Standard Orig->Lookup seems good.
|
// :TODO: need a good way to localize these ... Standard Orig->Lookup seems good.
|
||||||
"items" : [ "Login", "Apply", "Log Off" ]//,
|
"items" : [ "Login", "Apply", "Log Off" ]//,
|
||||||
//"itemSpacing" : 1
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"submit" : {
|
"submit" : {
|
||||||
|
@ -116,21 +110,14 @@
|
||||||
"form" : {
|
"form" : {
|
||||||
"0" : {
|
"0" : {
|
||||||
"BT12BT13ET1ET10ET2ET3ET4ET5ET6ET7ET8ET9TL11" : {
|
"BT12BT13ET1ET10ET2ET3ET4ET5ET6ET7ET8ET9TL11" : {
|
||||||
//
|
|
||||||
// :TODO: defaults { width : XX, ... } kinda thing would be nice
|
|
||||||
//
|
|
||||||
// "beforeViewsDraw" : "@method:location.js/myBeforeViewsDraw" -> myBeforeViewsDraw(views)
|
|
||||||
"mci" : {
|
"mci" : {
|
||||||
"ET1" : {
|
"ET1" : {
|
||||||
"focus" : true,
|
"focus" : true,
|
||||||
"argName" : "username",
|
"argName" : "username",
|
||||||
//"width" : 15,
|
|
||||||
"maxLength" : "@config:users.usernameMax"
|
"maxLength" : "@config:users.usernameMax"
|
||||||
},
|
},
|
||||||
"ET2" : {
|
"ET2" : {
|
||||||
"width" : 15,
|
|
||||||
"argName" : "realName",
|
"argName" : "realName",
|
||||||
//"width" : 15,
|
|
||||||
"maxLength" : 32
|
"maxLength" : 32
|
||||||
},
|
},
|
||||||
"ET3" : {
|
"ET3" : {
|
||||||
|
@ -145,34 +132,28 @@
|
||||||
},
|
},
|
||||||
"ET5" : {
|
"ET5" : {
|
||||||
"argName" : "location",
|
"argName" : "location",
|
||||||
//"width" : 15,
|
|
||||||
"maxLength" : 32
|
"maxLength" : 32
|
||||||
},
|
},
|
||||||
"ET6" : {
|
"ET6" : {
|
||||||
"argName" : "affils",
|
"argName" : "affils",
|
||||||
//"width" : 15,
|
|
||||||
"maxLength" : 32
|
"maxLength" : 32
|
||||||
},
|
},
|
||||||
"ET7" : {
|
"ET7" : {
|
||||||
"argName" : "email",
|
"argName" : "email",
|
||||||
//"width" : 15,
|
|
||||||
"maxLength" : 255
|
"maxLength" : 255
|
||||||
},
|
},
|
||||||
"ET8" : {
|
"ET8" : {
|
||||||
"argName" : "web",
|
"argName" : "web",
|
||||||
//"width" : 15,
|
|
||||||
"maxLength" : 255
|
"maxLength" : 255
|
||||||
},
|
},
|
||||||
"ET9" : {
|
"ET9" : {
|
||||||
"argName" : "password",
|
"argName" : "password",
|
||||||
"password" : true,
|
"password" : true,
|
||||||
//"width" : 15,
|
|
||||||
"maxLength" : "@config:users.passwordMax"
|
"maxLength" : "@config:users.passwordMax"
|
||||||
},
|
},
|
||||||
"ET10" : {
|
"ET10" : {
|
||||||
"argName" : "passwordConfirm",
|
"argName" : "passwordConfirm",
|
||||||
"password" : true,
|
"password" : true,
|
||||||
//"width" : 15,
|
|
||||||
"maxLength" : "@config:users.passwordMax"
|
"maxLength" : "@config:users.passwordMax"
|
||||||
},
|
},
|
||||||
"BT12" : {
|
"BT12" : {
|
||||||
|
@ -210,8 +191,8 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"newUserActive" : {
|
"newUserActive" : {
|
||||||
"art" : "STATS",
|
"art" : "userstats",
|
||||||
"prompt" : "pause",
|
//"prompt" : "pause",
|
||||||
"options" : {
|
"options" : {
|
||||||
// :TODO: implement MCI codes for this
|
// :TODO: implement MCI codes for this
|
||||||
"cls" : true
|
"cls" : true
|
||||||
|
@ -228,6 +209,7 @@
|
||||||
"items" : [
|
"items" : [
|
||||||
"Single Line Text Editing Views",
|
"Single Line Text Editing Views",
|
||||||
"Spinner & Toggle Views",
|
"Spinner & Toggle Views",
|
||||||
|
"Mask Edit Views",
|
||||||
"Vertical Menu Views",
|
"Vertical Menu Views",
|
||||||
"Horizontal Menu Views",
|
"Horizontal Menu Views",
|
||||||
"Art Display",
|
"Art Display",
|
||||||
|
@ -252,6 +234,10 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"value" : { "1" : 2 },
|
"value" : { "1" : 2 },
|
||||||
|
"action" : "@menu:demoMaskEditView"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value" : { "1" : 5 },
|
||||||
"action" : "@menu:demoArtDisplay"
|
"action" : "@menu:demoArtDisplay"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -279,7 +265,7 @@
|
||||||
"ET3" : {
|
"ET3" : {
|
||||||
"width" : 20,
|
"width" : 20,
|
||||||
"fillChar" : "-",
|
"fillChar" : "-",
|
||||||
// :TODO: fillColor
|
"styleSGR1" : "|00|36",
|
||||||
"maxLength" : 20
|
"maxLength" : 20
|
||||||
},
|
},
|
||||||
"ET4" : {
|
"ET4" : {
|
||||||
|
@ -340,6 +326,21 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"demoMaskEditView" : {
|
||||||
|
"art" : "demo_mask_edit_text_view1.ans",
|
||||||
|
"options" : { "cls" : true },
|
||||||
|
"form" : {
|
||||||
|
"0" : {
|
||||||
|
"BT5ME1ME2" : {
|
||||||
|
"mci" : {
|
||||||
|
"ME1" : {
|
||||||
|
"maskPattern" : "##/##/##"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"demoArtDisplay" : {
|
"demoArtDisplay" : {
|
||||||
"art" : "demo_selection_vm.ans",
|
"art" : "demo_selection_vm.ans",
|
||||||
"options" : { "cls" : true },
|
"options" : { "cls" : true },
|
||||||
|
|
|
@ -17,7 +17,10 @@
|
||||||
"menus" : {
|
"menus" : {
|
||||||
"matrix" : {
|
"matrix" : {
|
||||||
"VM1" : {
|
"VM1" : {
|
||||||
"itemSpacing" : 1
|
"itemSpacing" : 1,
|
||||||
|
"justify" : "center",
|
||||||
|
"width" : 12,
|
||||||
|
"focusTextStyle" : "l33t"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"apply" : {
|
"apply" : {
|
||||||
|
|
Loading…
Reference in New Issue