From 8b5152d66f033589bd89b55f9a6d4c5253f5afda Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Thu, 23 Jul 2015 22:23:44 -0600 Subject: [PATCH] * WIP pause prompt * prompt.json::prompts::pause is now a standard/required prompt * CT for current time MCI * Fix up config/theme defaults.dateTimeFormat -> dateFormat & timeFormat --- core/art.js | 2 +- core/config.js | 5 +- core/connect.js | 24 ++++++---- core/json_cache.js | 6 +-- core/mci_view_factory.js | 3 ++ core/menu_module.js | 2 +- core/menu_util.js | 2 +- core/theme.js | 88 ++++++++++++++++++++++++++++++++-- mods/prompt.json | 7 ++- mods/themes/NU-MAYA/theme.json | 2 +- 10 files changed, 119 insertions(+), 22 deletions(-) diff --git a/core/art.js b/core/art.js index f9f5352b..7c735f28 100644 --- a/core/art.js +++ b/core/art.js @@ -445,7 +445,7 @@ function display(options, cb) { } var extraInfo = { - height : parser.row - 1 + height : parser.row - 1, }; cb(null, mciMap, extraInfo); diff --git a/core/config.js b/core/config.js index ab7f7d54..1e69f803 100644 --- a/core/config.js +++ b/core/config.js @@ -91,8 +91,11 @@ function getDefaultConfig() { defaults : { theme : 'NU-MAYA', // :TODO: allow "*" here passwordChar : '*', // TODO: move to user ? - dateTimeFormat : { + dateFormat : { short : 'MM/DD/YYYY', + }, + timeFormat : { + short : 'h:mm tt', } }, diff --git a/core/connect.js b/core/connect.js index ef2e54e7..b39e5457 100644 --- a/core/connect.js +++ b/core/connect.js @@ -95,6 +95,22 @@ function displayBanner(term) { function connectEntry(client) { var term = client.term; + /* + theme.displayThemeArt({client : client, name : 'DM-ENIG.ANS'}, function onArt() { + return; + }); +*/ + /* + var iconv = require('iconv-lite'); + var art1 = require('fs').readFileSync('/home/nuskooler/dev/enigma-bbs/mods/art/DM-ENIG.ANS'); + console.log(typeof art1); + art1 = iconv.decode(art1, 'cp437'); + console.log(typeof art1) + term.output.write(art1); + //term.output.write(require('iconv-lite').encode(art1, 'CP437')); + return; + */ + // :TODO: Enthral for example queries cursor position & checks if it worked. This might be good // :TODO: How to detect e.g. if show/hide cursor can work? Probably can if CPR is avail @@ -130,14 +146,6 @@ function connectEntry(client) { // displayBanner(term); - /* - var art1 = require('fs').readFileSync('/home/nuskooler/dev/enigma-bbs/mods/themes/NU-MAYA/APPLY1.ANS'); - term.rawWrite(art1); - theme.displayThemeArt({client : client, name : 'APPLY1.ANS'}, function onArt() { - - }); -*/ - setTimeout(function onTimeout() { client.gotoMenuModule( { name : Config.firstMenu }); }, 500); diff --git a/core/json_cache.js b/core/json_cache.js index da0356b1..d3a95f00 100644 --- a/core/json_cache.js +++ b/core/json_cache.js @@ -52,13 +52,13 @@ JSONCache.prototype.getJSON = function(fileName, cb) { var filePath = paths.join(Config.paths.mods, fileName); if(filePath in this.cache) { - cb(null, this.cache[filePath]); + cb(null, this.cache[filePath], false); } else { this.reCacheJSONFromFile(filePath, function fileCached(err, json) { if(!err) { self.gaze.add(filePath); } - cb(err, json); + cb(err, json, true); }); } -} +}; diff --git a/core/mci_view_factory.js b/core/mci_view_factory.js index 802a4a85..1ce0aadb 100644 --- a/core/mci_view_factory.js +++ b/core/mci_view_factory.js @@ -54,7 +54,10 @@ MCIViewFactory.prototype.getPredefinedViewLabel = function(code) { ND : this.client.runtime.id.toString(), + // :TODO: change to CD for 'Current Date' DT : moment().format(this.client.currentTheme.helpers.getDateFormat()), + CT : moment().format(this.client.currentTheme.helpers.getTimeFormat()), + OS : { linux : 'Linux', diff --git a/core/menu_module.js b/core/menu_module.js index c92b9560..22341470 100644 --- a/core/menu_module.js +++ b/core/menu_module.js @@ -228,7 +228,7 @@ MenuModule.prototype.finishedLoading = function() { if('end' === self.menuConfig.pause || true === self.menuConfig.pause) { // :TODO: really need a client.term.pause() that uses the correct art/etc. - self.client.waitForKeyPress(function kp(ch, key) { + theme.displayThemePause( { client : self.client }, function keyPressed() { nextAction(); }); } else { diff --git a/core/menu_util.js b/core/menu_util.js index 413416bc..510cb6f0 100644 --- a/core/menu_util.js +++ b/core/menu_util.js @@ -43,7 +43,7 @@ function getMenuConfig(name, cb) { }, function loadPromptJSON(callback) { if(_.isString(menuConfig.prompt)) { - jsonCache.getJSON('prompt.json', function loaded(err, promptJson) { + jsonCache.getJSON('prompt.json', function loaded(err, promptJson, reCached) { callback(err, promptJson); }); } else { diff --git a/core/theme.js b/core/theme.js index 6951f027..8be357a5 100644 --- a/core/theme.js +++ b/core/theme.js @@ -3,8 +3,10 @@ var Config = require('./config.js').config; var art = require('./art.js'); +var ansi = require('./ansi_term.js'); var miscUtil = require('./misc_util.js'); var Log = require('./logger.js').log; +var jsonCache = require('./json_cache.js'); var fs = require('fs'); var paths = require('path'); @@ -18,6 +20,7 @@ exports.getThemeArt = getThemeArt; exports.getRandomTheme = getRandomTheme; exports.initAvailableThemes = initAvailableThemes; exports.displayThemeArt = displayThemeArt; +exports.displayThemePause = displayThemePause; // :TODO: use JSONCache here... may need to fancy it up a bit in order to have events for after re-cache, e.g. to update helpers below: function loadTheme(themeID, cb) { @@ -56,10 +59,20 @@ function loadTheme(themeID, cb) { getDateFormat : function(style) { style = style || 'short'; - var format = Config.defaults.dateTimeFormat[style] || 'MM/DD/YYYY'; - - if(_.has(theme, 'customization.defaults.dateTimeFormat')) { - return theme.customization.defaults.dateTimeFormat[style] || format; + var format = Config.defaults.dateFormat[style] || 'MM/DD/YYYY'; + + if(_.has(theme, 'customization.defaults.dateFormat')) { + return theme.customization.defaults.dateFormat[style] || format; + } + return format; + }, + getTimeFormat : function(style) { + style = style || 'short'; + + var format = Config.defaults.timeFormat[style] || 'h:mm tt'; + + if(_.has(theme, 'customization.defaults.timeFormat')) { + return theme.customization.defaults.timeFormat[style] || format; } return format; } @@ -175,3 +188,70 @@ function displayThemeArt(options, cb) { } }); } + +function displayThemePause(options, cb) { + // + // options.client + // options clearPrompt + // + assert(_.isObject(options.client)); + + if(!_.isBoolean(options.clearPrompt)) { + options.clearPrompt = true; + } + + // :TODO: Support animated pause prompts. Probably via MCI with AnimatedView + // :TODO: support prompts with a height > 1 + // :TODO: Prompt should support MCI codes in general + // ...this will be more complex due to cursor movement. Will need to track where teh cusor + // was before the prompt + filling MCI, then move back and erase correct # of lines + + async.waterfall( + [ + function loadPromptJSON(callback) { + jsonCache.getJSON('prompt.json', function loaded(err, promptJson) { + if(err) { + callback(err); + } else { + if(_.has(promptJson, [ 'prompts', 'pause' ] )) { + callback(null, promptJson.prompts.pause); + } else { + callback(new Error('Missing standard \'pause\' prompt')) + } + } + }); + }, + function displayPausePrompt(pausePrompt, callback) { + displayThemeArt( { client : options.client, name : pausePrompt.art }, function pauseDisplayed(err, mciMap, extraInfo) { + if(extraInfo) { + pauseHeight = extraInfo.height; + } + callback(null); + }); + }, + function pauseForUserInput(callback) { + options.client.waitForKeyPress(function keyPressed() { + callback(null); + }); + }, + function clearPauseArt(callback) { + if(options.clearPrompt) { + options.client.term.write(ansi.up(1) + ansi.deleteLine()); + } + callback(null); + } + , function debugPause(callback) { + setTimeout(function to() { + callback(null); + }, 4000); + } + + ], + function complete(err) { + if(err) { + Log.error(err); + } + cb(); + } + ); +} diff --git a/mods/prompt.json b/mods/prompt.json index e31e34a6..d1f4744f 100644 --- a/mods/prompt.json +++ b/mods/prompt.json @@ -16,6 +16,9 @@ } }, "pause" : { + // + // Any menu 'pause' will use this prompt + // "art" : "pause" /* "mci" : { @@ -37,7 +40,7 @@ * echoKey : false */ - }, + }/*, "standard" : { // any menu 'pause' will display this, pause for a key, then erase and move on "pause" : { @@ -47,7 +50,7 @@ }, "custom" : { - } + }*/ /* see notes in menu_module.js also ...how to allow for this to come from the theme first??? diff --git a/mods/themes/NU-MAYA/theme.json b/mods/themes/NU-MAYA/theme.json index c783c49f..3271d80c 100644 --- a/mods/themes/NU-MAYA/theme.json +++ b/mods/themes/NU-MAYA/theme.json @@ -8,7 +8,7 @@ "general" : { "passwordChar" : "φ" }, - "dateTimeFormat" : { + "dateFormat" : { "short" : "YYYY-MMM-DD" }, "mci" : {