* 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
This commit is contained in:
Bryan Ashby 2015-07-23 22:23:44 -06:00
parent 7f4c97329d
commit 8b5152d66f
10 changed files with 119 additions and 22 deletions

View file

@ -445,7 +445,7 @@ function display(options, cb) {
} }
var extraInfo = { var extraInfo = {
height : parser.row - 1 height : parser.row - 1,
}; };
cb(null, mciMap, extraInfo); cb(null, mciMap, extraInfo);

View file

@ -91,8 +91,11 @@ function getDefaultConfig() {
defaults : { defaults : {
theme : 'NU-MAYA', // :TODO: allow "*" here theme : 'NU-MAYA', // :TODO: allow "*" here
passwordChar : '*', // TODO: move to user ? passwordChar : '*', // TODO: move to user ?
dateTimeFormat : { dateFormat : {
short : 'MM/DD/YYYY', short : 'MM/DD/YYYY',
},
timeFormat : {
short : 'h:mm tt',
} }
}, },

View file

@ -95,6 +95,22 @@ function displayBanner(term) {
function connectEntry(client) { function connectEntry(client) {
var term = client.term; 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: 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 // :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); 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() { setTimeout(function onTimeout() {
client.gotoMenuModule( { name : Config.firstMenu }); client.gotoMenuModule( { name : Config.firstMenu });
}, 500); }, 500);

View file

@ -52,13 +52,13 @@ JSONCache.prototype.getJSON = function(fileName, cb) {
var filePath = paths.join(Config.paths.mods, fileName); var filePath = paths.join(Config.paths.mods, fileName);
if(filePath in this.cache) { if(filePath in this.cache) {
cb(null, this.cache[filePath]); cb(null, this.cache[filePath], false);
} else { } else {
this.reCacheJSONFromFile(filePath, function fileCached(err, json) { this.reCacheJSONFromFile(filePath, function fileCached(err, json) {
if(!err) { if(!err) {
self.gaze.add(filePath); self.gaze.add(filePath);
} }
cb(err, json); cb(err, json, true);
}); });
} }
} };

View file

@ -54,7 +54,10 @@ MCIViewFactory.prototype.getPredefinedViewLabel = function(code) {
ND : this.client.runtime.id.toString(), ND : this.client.runtime.id.toString(),
// :TODO: change to CD for 'Current Date'
DT : moment().format(this.client.currentTheme.helpers.getDateFormat()), DT : moment().format(this.client.currentTheme.helpers.getDateFormat()),
CT : moment().format(this.client.currentTheme.helpers.getTimeFormat()),
OS : { OS : {
linux : 'Linux', linux : 'Linux',

View file

@ -228,7 +228,7 @@ MenuModule.prototype.finishedLoading = function() {
if('end' === self.menuConfig.pause || true === self.menuConfig.pause) { if('end' === self.menuConfig.pause || true === self.menuConfig.pause) {
// :TODO: really need a client.term.pause() that uses the correct art/etc. // :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(); nextAction();
}); });
} else { } else {

View file

@ -43,7 +43,7 @@ function getMenuConfig(name, cb) {
}, },
function loadPromptJSON(callback) { function loadPromptJSON(callback) {
if(_.isString(menuConfig.prompt)) { if(_.isString(menuConfig.prompt)) {
jsonCache.getJSON('prompt.json', function loaded(err, promptJson) { jsonCache.getJSON('prompt.json', function loaded(err, promptJson, reCached) {
callback(err, promptJson); callback(err, promptJson);
}); });
} else { } else {

View file

@ -3,8 +3,10 @@
var Config = require('./config.js').config; var Config = require('./config.js').config;
var art = require('./art.js'); var art = require('./art.js');
var ansi = require('./ansi_term.js');
var miscUtil = require('./misc_util.js'); var miscUtil = require('./misc_util.js');
var Log = require('./logger.js').log; var Log = require('./logger.js').log;
var jsonCache = require('./json_cache.js');
var fs = require('fs'); var fs = require('fs');
var paths = require('path'); var paths = require('path');
@ -18,6 +20,7 @@ exports.getThemeArt = getThemeArt;
exports.getRandomTheme = getRandomTheme; exports.getRandomTheme = getRandomTheme;
exports.initAvailableThemes = initAvailableThemes; exports.initAvailableThemes = initAvailableThemes;
exports.displayThemeArt = displayThemeArt; 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: // :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) { function loadTheme(themeID, cb) {
@ -56,10 +59,20 @@ function loadTheme(themeID, cb) {
getDateFormat : function(style) { getDateFormat : function(style) {
style = style || 'short'; style = style || 'short';
var format = Config.defaults.dateTimeFormat[style] || 'MM/DD/YYYY'; var format = Config.defaults.dateFormat[style] || 'MM/DD/YYYY';
if(_.has(theme, 'customization.defaults.dateTimeFormat')) { if(_.has(theme, 'customization.defaults.dateFormat')) {
return theme.customization.defaults.dateTimeFormat[style] || format; 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; 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();
}
);
}

View file

@ -16,6 +16,9 @@
} }
}, },
"pause" : { "pause" : {
//
// Any menu 'pause' will use this prompt
//
"art" : "pause" "art" : "pause"
/* /*
"mci" : { "mci" : {
@ -37,7 +40,7 @@
* echoKey : false * echoKey : false
*/ */
}, }/*,
"standard" : { "standard" : {
// any menu 'pause' will display this, pause for a key, then erase and move on // any menu 'pause' will display this, pause for a key, then erase and move on
"pause" : { "pause" : {
@ -47,7 +50,7 @@
}, },
"custom" : { "custom" : {
} }*/
/* /*
see notes in menu_module.js also see notes in menu_module.js also
...how to allow for this to come from the theme first??? ...how to allow for this to come from the theme first???

View file

@ -8,7 +8,7 @@
"general" : { "general" : {
"passwordChar" : "φ" "passwordChar" : "φ"
}, },
"dateTimeFormat" : { "dateFormat" : {
"short" : "YYYY-MMM-DD" "short" : "YYYY-MMM-DD"
}, },
"mci" : { "mci" : {