我需要从读行界面获得响应,一切正常,但我想在问题的下一行输入答案,但现在我可以与问题一起输入答案。
async function IsAgreed() {
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
let options = ['yes', 'y', 'YES', 'Y'];
let response = await rl.question('Do you agree to execute ?');
return options.includes(response);
}
输出:
Do you agree to execute ?| <-- cursor is here
预期输出:
Do you agree to execute ?
| <-- I need to insert cursor here
我是编码新手,任何想法都会对我有帮助。
只需在问题末尾添加\n
\n
转义字符。将插入新行,以便您可以在问题的下一行输入答案。完成所有操作后不要忘记关闭 readline 界面
rl.close()
。