我有这样的功能:
const runInteractive = (rows, dups) => {
const keys = new Set(dups);
const questions = _(rows)
.filter(row => keys.has(row.key))
.groupBy(row => row.key)
.map((rows, key) => ({
type: 'list',
name: key.replace('.', ','),
message: `Pick a value for ${key}`,
choices: rows.map(row => ({ name: row.value, value: row, short: '✔' }))
}))
.value();
return inquirer
.prompt(questions)
.then(answers => _.sortBy(rows.filter(row => !keys.has(row.key)).concat(Object.values(answers)), row => row.key));
};
我从shebang节点脚本中调用它。
该过程正在显示查询者提示,然后死亡。
如何保持活动状态以便用户输入输入内容?
答案 0 :(得分:0)
我知道这个问题很旧,但是经过几天的苦苦挣扎,我发现了这个问题,并认为我会发布答案
至少在macOS / linux上,您可以执行以下操作-
#!/bin/bash
exec < /dev/tty;
node /path/to/node/file.js
查询者提示所在的地方file.js
。调用exec < /dev/tty
时,即使在没有TTY的上下文中执行脚本时,是否也可以捕获用户输入。