From 080d1727c2b12ea218ef75f96d9307b993f551d2 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 14 Nov 2018 22:47:20 -0700 Subject: [PATCH] WIP on real-time interruptions (ie: incoming message) Still need work on *when* they are allowed with good defaults, etc. --- core/menu_module.js | 32 ++++++++++++++++++-------------- core/user_interrupt_queue.js | 20 +++++++++++++++++--- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/core/menu_module.js b/core/menu_module.js index 1e68823c..bd75c94c 100644 --- a/core/menu_module.js +++ b/core/menu_module.js @@ -192,19 +192,7 @@ exports.MenuModule = class MenuModule extends PluginModule { async.whilst( () => this.client.interruptQueue.hasItems(), - next => { - this.client.interruptQueue.displayNext( (err, interruptItem) => { - if(err) { - return next(err); - } - - if(interruptItem.pause) { - return this.pausePrompt(next); - } - - return next(null); - }); - }, + next => this.client.interruptQueue.displayNext(next), err => { return cb(err); } @@ -212,7 +200,21 @@ exports.MenuModule = class MenuModule extends PluginModule { } attemptInterruptNow(interruptItem, cb) { - return cb(null, false); + if(true !== this.interruptable) { + return cb(null, false); // don't eat up the item; queue for later + } + + // + // Default impl: clear screen -> standard display -> reload menu + // + this.client.interruptQueue.displayWithItem(Object.assign({}, interruptItem, { cls : true }), err => { + if(err) { + return cb(err, false); + } + this.reload(err => { + return cb(err, err ? false : true); + }); + }); } getSaveState() { @@ -311,6 +313,8 @@ exports.MenuModule = class MenuModule extends PluginModule { } else { return gotoNextMenu(); } + } else { + this.enableInterruption(); } } diff --git a/core/user_interrupt_queue.js b/core/user_interrupt_queue.js index 1a62e063..e48fc2ea 100644 --- a/core/user_interrupt_queue.js +++ b/core/user_interrupt_queue.js @@ -35,8 +35,17 @@ module.exports = class UserInterruptQueue if(!_.isString(interruptItem.contents) && !_.isString(interruptItem.text)) { return; } + + // pause defaulted on interruptItem.pause = _.get(interruptItem, 'pause', true); - this.queue.push(interruptItem); + + this.client.currentMenuModule.attemptInterruptNow(interruptItem, (err, ateIt) => { + if(err) { + // :TODO: Log me + } else if(true !== ateIt) { + this.queue.push(interruptItem); + } + }); } hasItems() { @@ -61,8 +70,13 @@ module.exports = class UserInterruptQueue if(interruptItem.contents) { Art.display(this.client, interruptItem.contents, err => { - this.client.term.rawWrite('\r\n\r\n'); - return cb(err, interruptItem); + if(err) { + return cb(err); + } + //this.client.term.rawWrite('\r\n\r\n'); // :TODO: Prob optional based on contents vs text + this.client.currentMenuModule.pausePrompt( () => { + return cb(null); + }); }); } else { return this.client.term.write(pipeToAnsi(`${interruptItem.text}\r\n\r\n`, this.client), cb);