* Various cleanup + utility methods

This commit is contained in:
Bryan Ashby 2014-11-04 23:50:42 -07:00
parent d242546458
commit f2388ceed1
6 changed files with 68 additions and 21 deletions

View File

@ -368,26 +368,22 @@ function defaultEofFromExtension(ext) {
// cb(err, mci)
// :TODO: display({ art : art, client : client, ...}, cb)
function display(art, options, cb) {
if(!art || 0 === art.length) {
cb(new Error('Missing or empty art'));
return;
}
function display(options, cb) {
assert(
'undefined' !== typeof options &&
'undefined' !== typeof options.client &&
'undefined' !== typeof options.art,
'Missing required options');
if('undefined' === typeof options) {
cb(new Error('Missing options'));
return;
}
if('undefined' === typeof options.client) {
cb(new Error('Missing client in options'));
if(0 === options.art.length) {
cb(new Error('Empty art'));
return;
}
var cancelKeys = miscUtil.valueWithDefault(options.cancelKeys, []);
var pauseKeys = miscUtil.valueWithDefault(options.pauseKeys, []);
var pauseAtTermHeight = miscUtil.valueWithDefault(options.pauseAtTermHeight, false);
var mciReplaceChar = miscUtil.valueWithDefault(options.mciReplaceChar, '');
var mciReplaceChar = miscUtil.valueWithDefault(options.mciReplaceChar, ' ');
// :TODO: support pause/cancel & pause @ termHeight
var canceled = false;
@ -464,5 +460,5 @@ function display(art, options, cb) {
}
});
parser.parse(art);
parser.parse(options.art);
}

View File

@ -12,6 +12,7 @@ exports.getThemeInfo = getThemeInfo;
exports.getThemeArt = getThemeArt;
exports.getRandomTheme = getRandomTheme;
exports.initAvailableThemes = initAvailableThemes;
exports.displayThemeArt = displayThemeArt;
function getThemeInfo(themeID, cb) {
var path = paths.join(Config.paths.themes, themeID, 'theme_info.json');
@ -109,3 +110,15 @@ function getThemeArt(name, themeID, options, cb) {
}
});
}
function displayThemeArt(name, client, cb) {
getThemeArt(name, client.user.properties.art_theme_id, function onArt(err, theArt) {
if(err) {
cb(err);
} else {
art.display( { art : theArt, client : client }, function onDisplayed(err, mci) {
cb(err, mci);
});
}
});
}

View File

@ -10,14 +10,14 @@ var assert = require('assert');
exports.TickerTextView = TickerTextView;
TickerTextView = function(client, options) {
function TickerTextView(client, options) {
View.call(this, client, options);
var self = this;
this.text = this.options.text || '';
this.tickerStyle = this.options.tickerStyle || 'rightToLeft';
asssert(this.tickerStyle in TickerTextView.TickerStyles);
assert(this.tickerStyle in TickerTextView.TickerStyles);
// :TODO: Ticker |text| should have ANSI stripped before calculating any lengths/etc.
// strUtil.ansiTextLength(s)

Binary file not shown.

View File

@ -10,7 +10,9 @@ var modules = require('../core/modules.js');
//var view = require('../core/view.js');
var textView = require('../core/text_view.js');
var editTextView = require('../core/edit_text_view.js');
var viewController = require('../core/view_controller.js');
var ViewController = require('../core/view_controller.js').ViewController;
var async = require('async');
exports.moduleInfo = {
name : 'Matrix',
@ -20,6 +22,43 @@ exports.moduleInfo = {
exports.entryPoint = entryPoint;
function entryPoint(client) {
theme.displayThemeArt('MATRIX', client, function onMatrix(err, mciMap) {
if(mciMap.ET1 && mciMap.ET2 && mciMap.BN1 && mciMap.BN2 && mciMap.BN3) {
//
// Form via EditTextViews and ButtonViews
// * ET1 - userName
// * ET2 - password
// * BN1 - Login
// * BN2 - New
// * BN3 - Bye!
//
} else if(mciMap.VM1) {
//
// Menu via VerticalMenuView
//
// * VM1 - menu with the following items:
// 0 - Login
// 1 - New
// 2 - Bye!
//
var vc = new ViewController(client);
vc.on('submit', function onSubmit(form) {
});
vc.loadFromMCIMap(mciMap);
vc.setViewOrder();
// :TODO: Localize
vc.getView(1).setItems(['Login', 'New User', 'Goodbye!']);
vc.switchFocus(1);
}
});
}
/*
function entryPoint(client) {
var term = client.term;
@ -27,8 +66,6 @@ function entryPoint(client) {
// :TODO: types, random, and others? could come from conf.mods.matrix or such
//art.getArt('SO-CC1.ANS'/* 'MATRIX'*/, { types: ['.ans'], random: true}, function onArt(err, theArt) {
//client.user.properties.art_theme_id = '';
theme.getThemeArt('MCI_ET1.ANS', client.user.properties.art_theme_id, function onArt(err, theArt) {
//art.getArt('MATRIX_1.ANS', {}, function onArt(err, theArt) {
@ -64,3 +101,4 @@ function entryPoint(client) {
}
});
}
*/

View File

@ -28,7 +28,7 @@ function entryPoint(client) {
});
},
function displayArt(theArt, callback) {
art.display(theArt, { client : client, mciReplaceChar : ' ' }, function onDisplayed(err, mci) {
art.display( { art : theArt, client : client }, function onDisplayed(err, mci) {
callback(err, mci);
});
},