这涉及 node.js 的 vorpal CLI,如下所示:
const vorpal = require('vorpal')();
用户可以使用Ctrl-关闭 vorpal C,但是如何以编程方式关闭 vorpal?
例如,如果打开了 vorpal 终端会话,但 25 秒后没有收到进一步的标准输入,我想以编程方式关闭 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();
}
});