From d1b0663b5da2f4e83636a3e0d0c1e061648597cd Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 23 Mar 2015 23:12:19 -0600 Subject: [PATCH] * Some basic work on connecting modules --- core/ansi_term.js | 2 +- core/client.js | 13 ++++++++++--- core/menu_module.js | 41 ++++++++++++++++++++++++++++++++--------- core/theme.js | 2 +- mods/goodbye.js | 39 +++++++++++++++++++++++++++++++++++++++ mods/matrix.js | 15 ++++++++++++--- mods/menu.json | 14 ++++++++++++++ 7 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 mods/goodbye.js create mode 100644 mods/menu.json diff --git a/core/ansi_term.js b/core/ansi_term.js index bc4a5a61..39430955 100644 --- a/core/ansi_term.js +++ b/core/ansi_term.js @@ -209,7 +209,7 @@ function clearScreen() { } function resetScreen() { - return exports.goHome() + exports.eraseData(2); + return exports.goHome() + exports.reset() + exports.eraseData(2); } function normal() { diff --git a/core/client.js b/core/client.js index 37541dd6..a4a3f09c 100644 --- a/core/client.js +++ b/core/client.js @@ -161,11 +161,20 @@ function Client(input, output) { } while(0 !== dsrResponseRe.lastIndex); } }); + + self.detachCurrentMenuModule = function() { + if(self.currentMenuModule) { + self.currentMenuModule.leave(); + self.currentMenuModule = null; + } + }; } require('util').inherits(Client, stream); Client.prototype.end = function () { + this.detachCurrentMenuModule(); + return this.output.end.apply(this.output, arguments); }; @@ -193,9 +202,7 @@ Client.prototype.gotoMenuModule = function(name, cb) { // Assign a default missing module handler callback if none was provided cb = miscUtil.valueWithDefault(cb, self.defaultHandlerMissingMod()); - if(self.currentMenuModule) { - self.currentMenuModule.leave(); - } + self.detachCurrentMenuModule(); menuUtil.loadMenu(name, self, function onMenuModuleLoaded(err, modInst) { if(err) { diff --git a/core/menu_module.js b/core/menu_module.js index 45f54bcc..4890ac87 100644 --- a/core/menu_module.js +++ b/core/menu_module.js @@ -17,26 +17,37 @@ function MenuModule(menuConfig) { this.viewControllers = []; - this.loadArt = function() { + this.initSequence = function() { async.waterfall( [ + function beforeDisplayArt(callback) { + self.beforeArt(); + callback(null); + }, function displayArt(callback) { theme.displayThemeArt(self.menuConfig.art, self.client, function onArt(err, mciMap) { - callback(err, mciMap); + // :TODO: If the art simply is not found, or failed to load... we need to continue + if(err) { + console.log('TODO: log this error properly... maybe handle slightly diff.'); + } + callback(null, mciMap); }); }, - function artDisplayed(mciMap, callback) { - if(!mciMap) { - callback(null); - } else { + function afterArtDisplayed(mciMap, callback) { + if(mciMap) { self.mciReady(mciMap); } + + callback(null); } ], function onComplete(err) { if(err) { // :TODO: Log me!!! ... and what else? + console.log(err); } + + self.finishedLoading(); } ); }; @@ -47,12 +58,16 @@ require('util').inherits(MenuModule, PluginModule); MenuModule.prototype.enter = function(client) { this.client = client; assert(typeof client !== 'undefined'); + + this.initSequence(); }; MenuModule.prototype.leave = function() { - this.viewControllers.forEach(function onVC(vc) { - vc.detachClientEvents(); - }); + + var count = this.viewControllers.length; + for(var i = 0; i < count; ++i) { + this.viewControllers[i].detachClientEvents(); + } }; MenuModule.prototype.addViewController = function(vc) { @@ -60,5 +75,13 @@ MenuModule.prototype.addViewController = function(vc) { return vc; }; +MenuModule.prototype.beforeArt = function() { +}; + MenuModule.prototype.mciReady = function(mciMap) { + console.log('mciReady') +}; + +MenuModule.prototype.finishedLoading = function() { + console.log('finishedLoading') }; \ No newline at end of file diff --git a/core/theme.js b/core/theme.js index 434d63ac..5b750649 100644 --- a/core/theme.js +++ b/core/theme.js @@ -126,7 +126,7 @@ function displayThemeArt(name, client, cb) { } art.display( { art : artInfo.data, client : client, iceColors : iceColors }, function onDisplayed(err, mci) { - cb(err, mci); + cb(err, mci, artInfo); }); } }); diff --git a/mods/goodbye.js b/mods/goodbye.js new file mode 100644 index 00000000..6774315f --- /dev/null +++ b/mods/goodbye.js @@ -0,0 +1,39 @@ +/* jslint node: true */ +'use strict'; + +var MenuModule = require('../core/menu_module.js').MenuModule; +var ansi = require('../core/ansi_term.js'); + +exports.moduleInfo = { + name : 'Goodbye', + desc : 'Log off / Goodbye Module', + author : 'NuSkooler', +}; + +exports.getModule = GoodbyeModule; + +function GoodbyeModule(menuConfig) { + MenuModule.call(this, menuConfig); +} + +require('util').inherits(GoodbyeModule, MenuModule); + +GoodbyeModule.prototype.enter = function(client) { + GoodbyeModule.super_.prototype.enter.call(this, client); +}; + +GoodbyeModule.prototype.beforeArt = function() { + GoodbyeModule.super_.prototype.beforeArt.call(this); + + this.client.term.write(ansi.resetScreen()); +}; + +GoodbyeModule.prototype.mciReady = function(mciMap) { + GoodbyeModule.super_.prototype.mciReady.call(this, mciMap); +}; + +GoodbyeModule.prototype.finishedLoading = function() { + GoodbyeModule.super_.prototype.finishedLoading.call(this); + + this.client.end(); +}; \ No newline at end of file diff --git a/mods/matrix.js b/mods/matrix.js index 3236d45f..f335631a 100644 --- a/mods/matrix.js +++ b/mods/matrix.js @@ -14,13 +14,15 @@ var ViewController = require('../core/view_controller.js').ViewController; //var async = require('async'); +// :TODO: clean up requires +// :TODO: rename to matrix.js + exports.moduleInfo = { name : 'Matrix', desc : 'Standardish Matrix', author : 'NuSkooler', }; -//exports.entryPoint = entryPoint; exports.getModule = MatrixModule; @@ -32,10 +34,12 @@ require('util').inherits(MatrixModule, MenuModule); MatrixModule.prototype.enter = function(client) { MatrixModule.super_.prototype.enter.call(this, client); +}; - client.term.write(ansi.resetScreen()); +MatrixModule.prototype.beforeArt = function() { + MatrixModule.super_.prototype.beforeArt.call(this); - this.loadArt(); + this.client.term.write(ansi.resetScreen()); }; MatrixModule.prototype.mciReady = function(mciMap) { @@ -66,6 +70,11 @@ MatrixModule.prototype.mciReady = function(mciMap) { vc.on('submit', function onSubmit(form) { console.log(form); + + if(0 === form.id && 1 === form.viewId) { + // :TODO: fix me. Need to finalize form data. Current is kinda... meh. + self.client.gotoMenuModule('goodbye'); + } }); vc.loadFromMCIMap(mciMap); diff --git a/mods/menu.json b/mods/menu.json new file mode 100644 index 00000000..c24f4d6f --- /dev/null +++ b/mods/menu.json @@ -0,0 +1,14 @@ +{ + "matrix" : { + "art" : "matrix", + "module" : "matrix" + }, + "login" : { + "art" : "login", + "module" : "login" + }, + "goodbye" : { + "art" : "logoff", + "module" : "goodbye" + } +} \ No newline at end of file