From 32fdbab88d906cfb19fb35b4edb6b36a03c09515 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 25 Jun 2015 22:34:33 -0600 Subject: [PATCH] * Very very early work on FSE module --- core/art.js | 8 +- core/menu_module.js | 13 +-- core/theme.js | 4 +- core/view_controller.js | 34 +++--- .../{demo_fse.ans => demo_fse_local_user.ans} | Bin 535 -> 557 bytes mods/fse.js | 104 ++++++++++++++---- mods/menu.json | 10 +- 7 files changed, 117 insertions(+), 56 deletions(-) rename mods/art/{demo_fse.ans => demo_fse_local_user.ans} (52%) diff --git a/core/art.js b/core/art.js index 49dd47f4..59dfef1f 100644 --- a/core/art.js +++ b/core/art.js @@ -380,7 +380,6 @@ function defaultEofFromExtension(ext) { // :TODO: change to display(art, options, cb) // cb(err, mci) -// :TODO: display({ art : art, client : client, ...}, cb) function display(options, cb) { assert(_.isObject(options)); assert(_.isObject(options.client)); @@ -445,7 +444,11 @@ function display(options, cb) { // options.client.term.write(ansi.blinkNormal()); } - cb(null, mciMap); + var extraInfo = { + height : parser.row - 1 + }; + + cb(null, mciMap, extraInfo); } options.client.on('cursor position report', cprListener); @@ -454,6 +457,7 @@ function display(options, cb) { var nextPauseTermHeight = options.client.term.termHeight; var continous = false; + /* parser.on('row update', function rowUpdate(row) { if(row >= nextPauseTermHeight) { diff --git a/core/menu_module.js b/core/menu_module.js index f4a40786..9248921b 100644 --- a/core/menu_module.js +++ b/core/menu_module.js @@ -42,8 +42,8 @@ function MenuModule(options) { switch(artAsset.type) { case 'art' : - theme.displayThemeArt(dispOptions, function displayed(err, mciMap) { - cb(err, mciMap); + theme.displayThemeArt(dispOptions, function displayed(err, themeArtData) { + cb(err, { mciMap : themeArtData.mciMap, height : themeArtData.extraInfo.height } ); }); break; @@ -76,8 +76,8 @@ function MenuModule(options) { }, function displayMenuArt(callback) { if(_.isString(self.menuConfig.art)) { - self.displayArtAsset(self.menuConfig.art, function displayed(err, mciMap) { - mciData.menu = mciMap; + self.displayArtAsset(self.menuConfig.art, function displayed(err, artData) { + mciData.menu = artData.mciMap; callback(err); }); } else { @@ -165,13 +165,10 @@ MenuModule.prototype.standardMCIReadyHandler = function(mciData) { // * Standard/prefdefined MCI entries must load both (e.g. %BN is expected to resolve) // var self = this; - self.viewControllers = {}; - - //var vcOpts = { client : self.client }; _.forEach(mciData, function entry(mciMap, name) { assert('menu' === name || 'prompt' === name); - self.viewControllers[name] = new ViewController( { client : self.client } ); + self.addViewController(name, new ViewController( { client : self.client } )); }); var viewsReady = function(err) { diff --git a/core/theme.js b/core/theme.js index bf3322a8..021ce471 100644 --- a/core/theme.js +++ b/core/theme.js @@ -158,8 +158,8 @@ function displayThemeArt(options, cb) { font : options.font, }; - art.display(dispOptions, function displayed(err, mciMap) { - cb(err, mciMap, artInfo); + art.display(dispOptions, function displayed(err, mciMap, extraInfo) { + cb(err, { mciMap : mciMap, artInfo : artInfo, extraInfo : extraInfo } ); }); } }); diff --git a/core/view_controller.js b/core/view_controller.js index 76048b2f..5e664709 100644 --- a/core/view_controller.js +++ b/core/view_controller.js @@ -39,7 +39,8 @@ function ViewController(options) { // // Process key presses treating form submit mapped // keys special. Everything else is forwarded on to - // the focused View, if any. // + // the focused View, if any. + // if(key) { var submitViewId = self.submitKeyMap[key.name]; if(submitViewId) { @@ -412,6 +413,19 @@ ViewController.prototype.setViewOrder = function(order) { } }; +ViewController.prototype.redrawAll = function(initialFocusId) { + this.client.term.write(ansi.hideCursor()); + + for(var id in this.views) { + if(initialFocusId === id) { + continue; // will draw @ focus + } + this.views[id].redraw(); + } + + this.client.term.write(ansi.showCursor()); +}; + ViewController.prototype.loadFromPromptConfig = function(options, cb) { assert(_.isObject(options)); assert(_.isObject(options.mciMap)); @@ -459,14 +473,7 @@ ViewController.prototype.loadFromPromptConfig = function(options, cb) { callback(null); }, function drawAllViews(callback) { - self.client.term.write(ansi.hideCursor()); - - for(var id in self.views) { - if(initialFocusId === id) { - continue; // will draw @ focus - } - self.views[id].redraw(); - } + self.redrawAll(initialFocusId); callback(null); }, function setInitialViewFocus(callback) { @@ -609,14 +616,7 @@ ViewController.prototype.loadFromMenuConfig = function(options, cb) { callback(null); }, function drawAllViews(callback) { - self.client.term.write(ansi.hideCursor()); - - for(var id in self.views) { - if(initialFocusId === id) { - continue; // will draw @ focus - } - self.views[id].redraw(); - } + self.redrawAll(initialFocusId); callback(null); }, function setInitialViewFocus(callback) { diff --git a/mods/art/demo_fse.ans b/mods/art/demo_fse_local_user.ans similarity index 52% rename from mods/art/demo_fse.ans rename to mods/art/demo_fse_local_user.ans index ae013b3d608f2f3f202c1b0281c10aece5121169..33a5e8ebbb7b86efd53f25518a40d7fb67e73fd2 100644 GIT binary patch delta 67 zcmbQvvX*5+1E+$jYlxwAw3*q&79}vp2+Ua(#~~eUkgMt&Vmw)ZQD(9NBL|Cgv|;YV R4H1)D7;_odO#Z~E3IK3W6F>j} delta 49 zcmZ3>GM!~Y1B-ODx#7f4B`y%{EFEo_TQiX-VzL6G+++hrHV|_bV=m*g$sA0o0AcD4 AumAu6 diff --git a/mods/fse.js b/mods/fse.js index fe9ac239..df7cee3d 100644 --- a/mods/fse.js +++ b/mods/fse.js @@ -1,11 +1,12 @@ /* jslint node: true */ 'use strict'; -var MenuModule = require('../core/menu_module.js').MenuModule; +var MenuModule = require('../core/menu_module.js').MenuModule; +var ViewController = require('../core/view_controller.js').ViewController; -var async = require('async'); -var assert = require('assert'); -var _ = require('lodash'); +var async = require('async'); +var assert = require('assert'); +var _ = require('lodash'); exports.getModule = FullScreenEditorModule; @@ -18,36 +19,95 @@ exports.moduleInfo = { function FullScreenEditorModule(options) { MenuModule.call(this, options); - var self = this; - var args = options.menuConfig.args; + var self = this; + this.menuConfig = options.menuConfig; + this.editorType = this.menuConfig.config.editorType; - /* this.initSequence = function() { + var mciData = { }; + async.waterfall( [ function beforeDisplayArt(callback) { self.beforeArt(); callback(null); }, - function displayHeader(callback) { - if(_.isString(args.art.header)) { - self.displayArtAsset(args.art.header, function hdrDisplayed(err, mciMap) { - + function displayMainArt(callback) { + if(_.isString(self.menuConfig.art)) { + self.displayArtAsset(self.menuConfig.art, function frameDisplayed(err, artData) { + mciData.main = artData; + callback(err); }); + } else { + callback(null); // :TODO: should probably throw error... can't do much without this } - + }, + function afterArtDisplayed(callback) { + self.mciReady(mciData); callback(null); - }, - function displayBody(callback) { - - }, - function displayFooter(callback) { - } - ] + ], + function complete(err) { + + } ); }; - */ + + this.mciReadyHandlerNetMail = function(mciData) { + var vc = self.addViewController('main', new ViewController( { client : self.client } )); + + // :TODO: This can probably come from the normal mci configuration... + // additional mci stuff could be in config{} block. This should all be easily user-defined + var mciConfig = { + ET1 : { + width : 20, + text : 'Hello, World' + }, + ET2 : { + width : 10, + text : 'This is a longer string', + }, + MT3 : { + width : 80, + height : 17, + focus : true, + text : 'Ermergerd!\nHuzzah!' + } + + }; + + var initialFocusedId = 3; // editor + + async.waterfall( + [ + function createViews(callback) { + vc.createViewsFromMCI(mciData.main.mciMap, function viewsCreated(err) { + callback(err); + }); + }, + function applyThemeCustomization(callback) { + console.log('applyThemeCustomization...') + // :TODO: menuUtil.applyThemeCustomization() ... + // this should update local hard coded mci stuff for example to change colors, widths, blah blah + callback(null); + }, + function applyViewConfiguration(callback) { + console.log('applyViewConfiguration...') + + vc.applyViewConfig( { mci : mciConfig }, function configApplied(err, info) { + callback(err); + }); + }, + function drawAllViews(callback) { + vc.redrawAll(initialFocusedId); + callback(null); + }, + function setInitialFocus(callback) { + vc.switchFocus(initialFocusedId); // editor + } + ] + ); + }; } require('util').inherits(FullScreenEditorModule, MenuModule); @@ -56,3 +116,7 @@ FullScreenEditorModule.prototype.enter = function(client) { FullScreenEditorModule.super_.prototype.enter.call(this, client); }; +FullScreenEditorModule.prototype.mciReady = function(mciData) { + this['mciReadyHandler' + _.capitalize(this.editorType)](mciData); +}; + diff --git a/mods/menu.json b/mods/menu.json index 638c532e..441cf2be 100644 --- a/mods/menu.json +++ b/mods/menu.json @@ -432,14 +432,10 @@ }, "demoFullScreenEditor" : { "module" : "fse", - "art" : "demo_fse.ans", + "art" : "demo_fse_local_user.ans", "options" : { "cls" : true }, - "args" : { - "art" : { - "header" : "MSGHDR", - "body" : "MSGBODY", - "footer" : "MSGFTR" - } + "config" : { + "editorType" : "netMail" } }