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(
|
async.whilst(
|
||||||
() => this.client.interruptQueue.hasItems(),
|
() => this.client.interruptQueue.hasItems(),
|
||||||
next => {
|
next => this.client.interruptQueue.displayNext(next),
|
||||||
this.client.interruptQueue.displayNext( (err, interruptItem) => {
|
|
||||||
if(err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(interruptItem.pause) {
|
|
||||||
return this.pausePrompt(next);
|
|
||||||
}
|
|
||||||
|
|
||||||
return next(null);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
err => {
|
err => {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
|
@ -212,7 +200,21 @@ exports.MenuModule = class MenuModule extends PluginModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
attemptInterruptNow(interruptItem, cb) {
|
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() {
|
getSaveState() {
|
||||||
|
@ -311,6 +313,8 @@ exports.MenuModule = class MenuModule extends PluginModule {
|
||||||
} else {
|
} else {
|
||||||
return gotoNextMenu();
|
return gotoNextMenu();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.enableInterruption();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,17 @@ module.exports = class UserInterruptQueue
|
||||||
if(!_.isString(interruptItem.contents) && !_.isString(interruptItem.text)) {
|
if(!_.isString(interruptItem.contents) && !_.isString(interruptItem.text)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pause defaulted on
|
||||||
interruptItem.pause = _.get(interruptItem, 'pause', true);
|
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() {
|
hasItems() {
|
||||||
|
@ -61,8 +70,13 @@ module.exports = class UserInterruptQueue
|
||||||
|
|
||||||
if(interruptItem.contents) {
|
if(interruptItem.contents) {
|
||||||
Art.display(this.client, interruptItem.contents, err => {
|
Art.display(this.client, interruptItem.contents, err => {
|
||||||
this.client.term.rawWrite('\r\n\r\n');
|
if(err) {
|
||||||
return cb(err, interruptItem);
|
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 {
|
} else {
|
||||||
return this.client.term.write(pipeToAnsi(`${interruptItem.text}\r\n\r\n`, this.client), cb);
|
return this.client.term.write(pipeToAnsi(`${interruptItem.text}\r\n\r\n`, this.client), cb);
|
||||||
|
|
Loading…
Reference in New Issue