From a96af34a20c66ff9c20b47cc7383e9aa8cbc067b Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 14 May 2015 23:01:00 -0600 Subject: [PATCH] * Lots of code cleanup * New standard MCI codes for labels * WIP MaskEditTextView * Extra styles for EditTextView --- core/bbs.js | 26 +++++++++-- core/config.js | 2 +- core/edit_text_view.js | 3 +- core/mask_edit_text_view.js | 56 +++++++++++++++++++++--- core/mci_view_factory.js | 58 +++++++++++++++---------- core/menu_module.js | 6 +-- core/text_view.js | 2 +- core/view.js | 5 +++ core/view_controller.js | 2 + mods/art/demo_mask_edit_text_view1.ans | Bin 0 -> 638 bytes mods/menu.json | 47 ++++++++++---------- mods/themes/NU-MAYA/theme.json | 5 ++- 12 files changed, 150 insertions(+), 62 deletions(-) create mode 100644 mods/art/demo_mask_edit_text_view1.ans diff --git a/core/bbs.js b/core/bbs.js index 9214d147..ac8fc0bd 100644 --- a/core/bbs.js +++ b/core/bbs.js @@ -169,8 +169,6 @@ function startListening() { }); client.on('end', function onClientEnd() { - logger.log.info({ clientId : client.runtime.id }, 'Client disconnected'); - removeClient(client); }); @@ -192,7 +190,20 @@ function startListening() { function addNewClient(client) { 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; } @@ -200,7 +211,14 @@ function removeClient(client) { var i = clientConnections.indexOf(client); if(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' + ); } } diff --git a/core/config.js b/core/config.js index fd051bdd..816e3c6a 100644 --- a/core/config.js +++ b/core/config.js @@ -79,7 +79,7 @@ function getDefaultConfig() { users : { usernameMin : 2, - usernameMax : 22, + usernameMax : 16, usernamePattern : '^[A-Za-z0-9~!@#$%^&*()\\-\\_+]+$', passwordMin : 6, passwordMax : 128, diff --git a/core/edit_text_view.js b/core/edit_text_view.js index a98ff1c7..c60bd49c 100644 --- a/core/edit_text_view.js +++ b/core/edit_text_view.js @@ -23,7 +23,8 @@ function EditTextView(options) { this.cursorPos = { x : 0 }; 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()); }; } diff --git a/core/mask_edit_text_view.js b/core/mask_edit_text_view.js index 6469bea5..4b54dbf5 100644 --- a/core/mask_edit_text_view.js +++ b/core/mask_edit_text_view.js @@ -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); diff --git a/core/mci_view_factory.js b/core/mci_view_factory.js index 4a0386e7..13ce7802 100644 --- a/core/mci_view_factory.js +++ b/core/mci_view_factory.js @@ -7,6 +7,7 @@ var ButtonView = require('./button_view.js').ButtonView; var VerticalMenuView = require('./vertical_menu_view.js').VerticalMenuView; var SpinnerMenuView = require('./spinner_menu_view.js').SpinnerMenuView; var ToggleMenuView = require('./toggle_menu_view.js').ToggleMenuView; +var MaskEditTextView = require('./mask_edit_text_view.js').MaskEditTextView; var Config = require('./config.js').config; var ansi = require('./ansi_term.js'); @@ -23,32 +24,37 @@ function MCIViewFactory(client) { } 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; - case 'UR' : label = this.client.user.properties.real_name; break; - case 'LO' : label = this.client.user.properties.location; break; + return { + BN : Config.general.boardName, + VL : 'ENiGMA½ v' + packageJson.version, + VN : packageJson.version, - case 'OS' : - switch(os.platform()) { - case 'linux' : label = 'Linux'; break; - case 'darwin' : label = 'OS X'; break; - case 'win32' : label = 'Windows'; break; - case 'sunos' : label = 'SunOS'; break; - default : label = os.type(); break; - } - break; + UN : this.client.user.username, + UI : this.client.user.userId, + UG : _.values(this.client.user.groups).join(', '), + UR : this.client.user.properties.real_name, + LO : this.client.user.properties.location, + UA : this.client.user.properties.age, + US : this.client.user.properties.sex, + UE : this.client.user.properties.email_address, + 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; - case 'SC' : label = os.cpus()[0].model; break; - } + OS : { + 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) { @@ -111,6 +117,14 @@ MCIViewFactory.prototype.createFromMCI = function(mci) { view = new EditTextView(options); break; + // Masked Edit Text + case 'ME' : + setOption(0, 'textStyle'); + setFocusOption(0, 'focusTextStyle'); + + view = new MaskEditTextView(options); + break; + // Pre-defined Label (Text View) case 'PL' : if(mci.args.length > 0) { diff --git a/core/menu_module.js b/core/menu_module.js index f1bb4890..f4a40786 100644 --- a/core/menu_module.js +++ b/core/menu_module.js @@ -80,11 +80,11 @@ function MenuModule(options) { mciData.menu = mciMap; callback(err); }); - } else { + } else { callback(null); } }, - function moveToPromptLocation(callback) { + function moveToPromptLocation(callback) { if(self.menuConfig.prompt) { // :TODO: fetch and move cursor to prompt location, if supplied. See notes/etc. on placements } @@ -106,7 +106,7 @@ function MenuModule(options) { mciData.prompt = mciMap; callback(err); }); - } else { + } else { callback(null); } }, diff --git a/core/text_view.js b/core/text_view.js index 23c1418f..112860f9 100644 --- a/core/text_view.js +++ b/core/text_view.js @@ -80,7 +80,7 @@ function TextView(options) { this.fillChar, this.justify, this.hasFocus ? this.getFocusSGR() : this.getSGR(), - this.getSGR() // :TODO: use extended style color if avail + this.getStyleSGR(1) || this.getSGR() )); }; diff --git a/core/view.js b/core/view.js index 8705b830..5b7c8656 100644 --- a/core/view.js +++ b/core/view.js @@ -191,6 +191,11 @@ View.prototype.getSGR = function() { return this.ansiSGR; }; +View.prototype.getStyleSGR = function(x) { + assert(_.isNumber(x)); + return this['styleSGR' + x]; +} + View.prototype.getFocusSGR = function() { return this.ansiFocusSGR; }; diff --git a/core/view_controller.js b/core/view_controller.js index 8aea7935..d64f77ad 100644 --- a/core/view_controller.js +++ b/core/view_controller.js @@ -189,6 +189,8 @@ function ViewController(options) { setViewProp('textMaskChar', function(v) { view.textMaskChar = v.substr(0, 1); }); setViewProp('justify'); setViewProp('textOverflow'); + + setViewProp('maskPattern', function(v) { view.setMaskPattern(v); }); setViewProp('maxLength'); diff --git a/mods/art/demo_mask_edit_text_view1.ans b/mods/art/demo_mask_edit_text_view1.ans new file mode 100644 index 0000000000000000000000000000000000000000..7e75677b01b0e6b8a64f8e9271468584f6dc9ae1 GIT binary patch literal 638 zcmb`DO;5r=5QfW@1TWs?G8ZpKk}Xh4-~_dPBw`3u64Q8C=x8@|7t>upe!Pi0EvuM# zbepuDnRlLdXPOBcblIT8WTOtyO#DHoClmYA3FMgTRg?-d7r3JglP&wP;y_Lc)SBcn znuRWD)=;3?6p9MOd1=&%N?a!IgfhA;Fxme}UsPfy<6;l*gca(oYzX7&L+ja!dE2Q2Wr ZpEb{`)h6DFSDw@R(HQ2p!z%iIe*xs theme/draw.js::myMethod(opts) @@ -57,7 +52,6 @@ "focus" : true, // :TODO: need a good way to localize these ... Standard Orig->Lookup seems good. "items" : [ "Login", "Apply", "Log Off" ]//, - //"itemSpacing" : 1 } }, "submit" : { @@ -116,21 +110,14 @@ "form" : { "0" : { "BT12BT13ET1ET10ET2ET3ET4ET5ET6ET7ET8ET9TL11" : { - // - // :TODO: defaults { width : XX, ... } kinda thing would be nice - // - // "beforeViewsDraw" : "@method:location.js/myBeforeViewsDraw" -> myBeforeViewsDraw(views) "mci" : { "ET1" : { "focus" : true, "argName" : "username", - //"width" : 15, "maxLength" : "@config:users.usernameMax" }, "ET2" : { - "width" : 15, "argName" : "realName", - //"width" : 15, "maxLength" : 32 }, "ET3" : { @@ -145,34 +132,28 @@ }, "ET5" : { "argName" : "location", - //"width" : 15, "maxLength" : 32 }, "ET6" : { "argName" : "affils", - //"width" : 15, "maxLength" : 32 }, "ET7" : { "argName" : "email", - //"width" : 15, "maxLength" : 255 }, "ET8" : { "argName" : "web", - //"width" : 15, "maxLength" : 255 }, "ET9" : { "argName" : "password", "password" : true, - //"width" : 15, "maxLength" : "@config:users.passwordMax" }, "ET10" : { "argName" : "passwordConfirm", "password" : true, - //"width" : 15, "maxLength" : "@config:users.passwordMax" }, "BT12" : { @@ -210,8 +191,8 @@ } }, "newUserActive" : { - "art" : "STATS", - "prompt" : "pause", + "art" : "userstats", + //"prompt" : "pause", "options" : { // :TODO: implement MCI codes for this "cls" : true @@ -228,6 +209,7 @@ "items" : [ "Single Line Text Editing Views", "Spinner & Toggle Views", + "Mask Edit Views", "Vertical Menu Views", "Horizontal Menu Views", "Art Display", @@ -252,6 +234,10 @@ }, { "value" : { "1" : 2 }, + "action" : "@menu:demoMaskEditView" + }, + { + "value" : { "1" : 5 }, "action" : "@menu:demoArtDisplay" } ] @@ -279,7 +265,7 @@ "ET3" : { "width" : 20, "fillChar" : "-", - // :TODO: fillColor + "styleSGR1" : "|00|36", "maxLength" : 20 }, "ET4" : { @@ -340,6 +326,21 @@ } } }, + "demoMaskEditView" : { + "art" : "demo_mask_edit_text_view1.ans", + "options" : { "cls" : true }, + "form" : { + "0" : { + "BT5ME1ME2" : { + "mci" : { + "ME1" : { + "maskPattern" : "##/##/##" + } + } + } + } + } + }, "demoArtDisplay" : { "art" : "demo_selection_vm.ans", "options" : { "cls" : true }, diff --git a/mods/themes/NU-MAYA/theme.json b/mods/themes/NU-MAYA/theme.json index 7594bf5c..7f829015 100644 --- a/mods/themes/NU-MAYA/theme.json +++ b/mods/themes/NU-MAYA/theme.json @@ -17,7 +17,10 @@ "menus" : { "matrix" : { "VM1" : { - "itemSpacing" : 1 + "itemSpacing" : 1, + "justify" : "center", + "width" : 12, + "focusTextStyle" : "l33t" } }, "apply" : {