Add 'write' access for post FSE

+ hasMessageConfAndAreaWrite()
+ MenuModule helpers: gotoMenuOrPrev(), gotoMenuOrShowMessage(). These will likely replace many other pieces of code soon.
This commit is contained in:
Bryan Ashby 2019-09-16 22:05:03 -06:00
parent 7783262af6
commit 1fdaaf5633
No known key found for this signature in database
GPG key ID: B49EB437951D2542
3 changed files with 68 additions and 5 deletions

View file

@ -259,6 +259,44 @@ exports.MenuModule = class MenuModule extends PluginModule {
return this.client.menuStack.goto(name, options, cb);
}
gotoMenuOrPrev(name, options, cb) {
this.client.menuStack.goto(name, options, err => {
if(!err) {
if(cb) {
return cb(null);
}
}
return this.prevMenu(cb);
});
}
gotoMenuOrShowMessage(name, message, options, cb) {
if(!cb && _.isFunction(options)) {
cb = options;
options = {};
}
options = options || { clearScreen: true };
this.gotoMenu(name, options, err => {
if(err) {
if(options.clearScreen) {
this.client.term.rawWrite(ansi.resetScreen());
}
this.client.term.write(`${message}\n`);
return this.pausePrompt( () => {
return this.prevMenu(cb);
});
}
if(cb) {
return cb(null);
}
});
}
reload(cb) {
const prevMenu = this.client.menuStack.pop();
prevMenu.instance.leave();