I want to have normal .command()
handler that does some async calls, then decides if it will output something or throw the user into a mode. Is that possible?
If yes, how cat I set the delimiter based on my async calls? Can I set a custom .action()
function for this mode dynamically?
Alternatively, is it possible to pass a context to this dynamically created mode?
You can create a second (or multiple) instance of Vorpal, with an entirely different set of commands. These could also be declared these on the fly.
By calling vorpal.show()
on the new instance, this would "detach" the UI from the old Vorpal onto the new for the duration of that "mode", and it would appear to the user that you got an entirely new set of commands, delimiter, etc.
var modeA = new Vorpal().delimiter('fooland:');
var modeB = new Vorpal().delimiter('barland:');
modeA.command('foo'); // ...
modeB.command('bar'); // ...
// Only foo is present as a command.
modeA.show();
setTimeout(function(){
// Now bar is present as a command instead.
modeB.show();
}, 5000);