* ansiPrepOptions support for displaying art
* simplify proxy of options along call path * general improvements
This commit is contained in:
parent
e24511678d
commit
fbffe2873c
|
@ -12,6 +12,7 @@ const ViewController = require('./view_controller.js').ViewController;
|
||||||
const Errors = require('./enig_error.js').Errors;
|
const Errors = require('./enig_error.js').Errors;
|
||||||
const ErrorReasons = require('./enig_error.js').ErrorReasons;
|
const ErrorReasons = require('./enig_error.js').ErrorReasons;
|
||||||
const Events = require('./events.js');
|
const Events = require('./events.js');
|
||||||
|
const AnsiPrep = require('./ansi_prep.js');
|
||||||
|
|
||||||
const fs = require('graceful-fs');
|
const fs = require('graceful-fs');
|
||||||
const paths = require('path');
|
const paths = require('path');
|
||||||
|
@ -511,26 +512,47 @@ function displayThemeArt(options, cb) {
|
||||||
assert(_.isObject(options.client));
|
assert(_.isObject(options.client));
|
||||||
assert(_.isString(options.name));
|
assert(_.isString(options.name));
|
||||||
|
|
||||||
getThemeArt(options, (err, artInfo) => {
|
async.waterfall(
|
||||||
if(err) {
|
[
|
||||||
return cb(err);
|
function getArt(callback) {
|
||||||
|
return getThemeArt(options, callback);
|
||||||
|
},
|
||||||
|
function prepWork(artInfo, callback) {
|
||||||
|
if(_.isObject(options.ansiPrepOptions)) {
|
||||||
|
AnsiPrep(
|
||||||
|
artInfo.data,
|
||||||
|
options.ansiPrepOptions,
|
||||||
|
(err, prepped) => {
|
||||||
|
if(!err && prepped) {
|
||||||
|
artInfo.data = prepped;
|
||||||
|
return callback(null, artInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return callback(null, artInfo);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function disp(artInfo, callback) {
|
||||||
|
const displayOpts = {
|
||||||
|
sauce : artInfo.sauce,
|
||||||
|
font : options.font,
|
||||||
|
trailingLF : options.trailingLF,
|
||||||
|
};
|
||||||
|
art.display(options.client, artInfo.data, displayOpts, (err, mciMap, extraInfo) => {
|
||||||
|
return callback(err, { mciMap : mciMap, artInfo : artInfo, extraInfo : extraInfo } );
|
||||||
|
});
|
||||||
|
}
|
||||||
|
],
|
||||||
|
(err, artData) => {
|
||||||
|
return cb(err, artData);
|
||||||
}
|
}
|
||||||
// :TODO: just use simple merge of options -> displayOptions
|
);
|
||||||
const displayOpts = {
|
|
||||||
sauce : artInfo.sauce,
|
|
||||||
font : options.font,
|
|
||||||
trailingLF : options.trailingLF,
|
|
||||||
};
|
|
||||||
|
|
||||||
art.display(options.client, artInfo.data, displayOpts, (err, mciMap, extraInfo) => {
|
|
||||||
return cb(err, { mciMap : mciMap, artInfo : artInfo, extraInfo : extraInfo } );
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayThemedPrompt(name, client, options, cb) {
|
function displayThemedPrompt(name, client, options, cb) {
|
||||||
|
|
||||||
const useTempViewController = _.isUndefined(options.viewController);
|
const usingTempViewController = _.isUndefined(options.viewController);
|
||||||
|
|
||||||
async.waterfall(
|
async.waterfall(
|
||||||
[
|
[
|
||||||
|
@ -549,8 +571,8 @@ function displayThemedPrompt(name, client, options, cb) {
|
||||||
// doing so messes things up -- most terminals that support font
|
// doing so messes things up -- most terminals that support font
|
||||||
// changing can only display a single font at at time.
|
// changing can only display a single font at at time.
|
||||||
//
|
//
|
||||||
|
const dispOptions = Object.assign( {}, options, promptConfig.options );
|
||||||
// :TODO: We can use term detection to do nifty things like avoid this kind of kludge:
|
// :TODO: We can use term detection to do nifty things like avoid this kind of kludge:
|
||||||
const dispOptions = Object.assign( {}, promptConfig.options );
|
|
||||||
if(!options.clearScreen) {
|
if(!options.clearScreen) {
|
||||||
dispOptions.font = 'not_really_a_font!'; // kludge :)
|
dispOptions.font = 'not_really_a_font!'; // kludge :)
|
||||||
}
|
}
|
||||||
|
@ -582,28 +604,29 @@ function displayThemedPrompt(name, client, options, cb) {
|
||||||
client.term.rawWrite(ansi.queryPos());
|
client.term.rawWrite(ansi.queryPos());
|
||||||
},
|
},
|
||||||
function createMCIViews(promptConfig, artInfo, callback) {
|
function createMCIViews(promptConfig, artInfo, callback) {
|
||||||
const tempViewController = useTempViewController ? new ViewController( { client : client } ) : options.viewController;
|
const assocViewController = usingTempViewController ? new ViewController( { client : client } ) : options.viewController;
|
||||||
|
|
||||||
const loadOpts = {
|
const loadOpts = {
|
||||||
promptName : name,
|
promptName : name,
|
||||||
mciMap : artInfo.mciMap,
|
mciMap : artInfo.mciMap,
|
||||||
config : promptConfig,
|
config : promptConfig,
|
||||||
|
submitNotify : options.submitNotify,
|
||||||
};
|
};
|
||||||
|
|
||||||
tempViewController.loadFromPromptConfig(loadOpts, () => {
|
assocViewController.loadFromPromptConfig(loadOpts, () => {
|
||||||
return callback(null, artInfo, tempViewController);
|
return callback(null, artInfo, assocViewController);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function pauseForUserInput(artInfo, tempViewController, callback) {
|
function pauseForUserInput(artInfo, assocViewController, callback) {
|
||||||
if(!options.pause) {
|
if(!options.pause) {
|
||||||
return callback(null, artInfo, tempViewController);
|
return callback(null, artInfo, assocViewController);
|
||||||
}
|
}
|
||||||
|
|
||||||
client.waitForKeyPress( () => {
|
client.waitForKeyPress( () => {
|
||||||
return callback(null, artInfo, tempViewController);
|
return callback(null, artInfo, assocViewController);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function clearPauseArt(artInfo, tempViewController, callback) {
|
function clearPauseArt(artInfo, assocViewController, callback) {
|
||||||
if(options.clearPrompt) {
|
if(options.clearPrompt) {
|
||||||
if(artInfo.startRow && artInfo.height) {
|
if(artInfo.startRow && artInfo.height) {
|
||||||
client.term.rawWrite(ansi.goto(artInfo.startRow, 1));
|
client.term.rawWrite(ansi.goto(artInfo.startRow, 1));
|
||||||
|
@ -615,19 +638,19 @@ function displayThemedPrompt(name, client, options, cb) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return callback(null, tempViewController);
|
return callback(null, assocViewController, artInfo);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
(err, tempViewController) => {
|
(err, assocViewController, artInfo) => {
|
||||||
if(err) {
|
if(err) {
|
||||||
client.log.warn( { error : err.message }, `Failed displaying "${name}" prompt` );
|
client.log.warn( { error : err.message }, `Failed displaying "${name}" prompt` );
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tempViewController && useTempViewController) {
|
if(assocViewController && usingTempViewController) {
|
||||||
tempViewController.detachClientEvents();
|
assocViewController.detachClientEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
return cb(null);
|
return cb(null, artInfo);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -668,14 +691,7 @@ function displayThemedAsset(assetSpec, client, options, cb) {
|
||||||
return cb(new Error('Asset not found: ' + assetSpec));
|
return cb(new Error('Asset not found: ' + assetSpec));
|
||||||
}
|
}
|
||||||
|
|
||||||
// :TODO: just use simple merge of options -> displayOptions
|
const dispOpts = Object.assign( {}, options, { client, name : artAsset.asset } );
|
||||||
var dispOpts = {
|
|
||||||
name : artAsset.asset,
|
|
||||||
client : client,
|
|
||||||
font : options.font,
|
|
||||||
trailingLF : options.trailingLF,
|
|
||||||
};
|
|
||||||
|
|
||||||
switch(artAsset.type) {
|
switch(artAsset.type) {
|
||||||
case 'art' :
|
case 'art' :
|
||||||
displayThemeArt(dispOpts, function displayed(err, artData) {
|
displayThemeArt(dispOpts, function displayed(err, artData) {
|
||||||
|
|
Loading…
Reference in New Issue