vorpal
vorpal copied to clipboard
How close vorpal programmatically
The user can close vorpal with ctrl+c, but how can I close vorpal programmatically?
For example, if a vorpal terminal session is opened, but no further stdin is received after 25 seconds, I want to programmatically close vorpal, here is what my code looks like:
vorpal
.delimiter(shortCWD + chalk.magenta(' / suman>'))
.show();
const to = setTimeout(function () {
vorpal.close(); // >>> I want to programmatically close vorpal...but vorpal.close() is not a function
process.stdin.end();
log.error('No stdin was received after 25 seconds..closing...');
p.killAllImmediately();
process.exit(0);
}, 25000); // if no stdin has been received after 25 seconds
process.stdin
.setEncoding('utf8')
.resume()
.on('data', function customOnData(data: string) {
clearTimeout(to);
if (String(data) === 'q') {
log.warning('killing all active workers.');
p.killAllActiveWorkers();
}
});
I asked a question on SO about this, if someone wants points: https://stackoverflow.com/questions/47128158/close-vorpal-instance-programmatically
@dthree @milesj hopefully this is a quick one, help appreciated
I left a quick answer on Stack Overflow in case other people find that as well, but you can use vorpal.exec("exit");