这涉及用于node.js的vorpal CLI,如下所示:
const vorpal = require('vorpal')();
用户可以使用Ctrl-C关闭vorpal,但是如何以编程方式关闭vorpal?
例如,如果打开了vorpal终端会话,但在25秒后没有收到任何进一步的stdin,我想以编程方式关闭vorpal,这是我的代码:
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();
}
});
最佳答案
尽管Vorpal没有关闭功能,但是您可以使用exit
或exec
以编程方式运行本机execSync
命令。您可能还对hide
感兴趣,因为它们只是隐藏Vorpal。
码:
vorpal.exec("exit");
关于javascript - 以编程方式关闭Vorpal实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47128158/