WIP on real-time interruptions (ie: incoming message)
Still need work on *when* they are allowed with good defaults, etc.
This commit is contained in:
parent
4025c3c643
commit
080d1727c2
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue