* Start work on pausable ANSI display/etc.

This commit is contained in:
Bryan Ashby 2015-05-03 17:35:55 -06:00
parent 3f92a7949d
commit 5a00d219f8
4 changed files with 133 additions and 10 deletions

View file

@ -382,17 +382,17 @@ function defaultEofFromExtension(ext) {
// :TODO: display({ art : art, client : client, ...}, cb)
function display(options, cb) {
assert(
'undefined' !== typeof options &&
'undefined' !== typeof options.client &&
'undefined' !== typeof options.art,
'Missing required options');
assert(_.isObject(options));
assert(_.isObject(options.client));
assert(!_.isUndefined(options.art));
if(0 === options.art.length) {
cb(new Error('Empty art'));
return;
}
// pause = none/off | end | termHeight | [ "key1", "key2", ... ]
var cancelKeys = miscUtil.valueWithDefault(options.cancelKeys, []);
var pauseKeys = miscUtil.valueWithDefault(options.pauseKeys, []);
var pauseAtTermHeight = miscUtil.valueWithDefault(options.pauseAtTermHeight, false);
@ -426,7 +426,7 @@ function display(options, cb) {
var generatedId = 100;
var onCPR = function(pos) {
var cprListener = function(pos) {
if(mciPosQueue.length > 0) {
var forMapItem = mciPosQueue.shift();
mciMap[forMapItem].position = pos;
@ -438,7 +438,7 @@ function display(options, cb) {
};
function completed() {
options.client.removeListener('cursor position report', onCPR);
options.client.removeListener('cursor position report', cprListener);
parser.removeAllListeners(); // :TODO: Necessary???
if(iceColors) {
@ -448,7 +448,22 @@ function display(options, cb) {
cb(null, mciMap);
}
options.client.on('cursor position report', onCPR);
options.client.on('cursor position report', cprListener);
//options.pause = 'termHeight'; // :TODO: remove!!
var nextTermHeight = options.client.termHeight;
parser.on('row update', function rowUpdate(row) {
if(row >= nextTermHeight) {
if('termHeight' === options.pause) {
options.client.waitForKeyPress(function kp(k) {
parser.parse();
});
parser.stop();
}
nextTermHeight *= 2;
}
});
parser.on('mci', function mciEncountered(mciInfo) {
@ -463,6 +478,7 @@ function display(options, cb) {
*/
// :TODO: ensure generatedId's do not conflict with any |id|
// :TODO: Bug here - should only generate & increment ID's for the initial entry, not the "focus" version
var id = !_.isNumber(mciInfo.id) ? generatedId++ : mciInfo.id;
var mapKey = mciInfo.mci + id;
var mapEntry = mciMap[mapKey];
@ -522,5 +538,7 @@ function display(options, cb) {
options.client.term.write(ansi.blinkToBrightIntensity());
}
parser.parse(options.art);
parser.reset(options.art);
parser.parse();
//parser.parse(options.art);
}