【发布时间】:2019-05-07 19:38:08
【问题描述】:
当我按住键盘上的 ENTER 时,readline 模块将向我的可写流输出空行(在本例中为 process.stdout)。
但由于我不想让空行弄乱我的控制台,我想以某种方式阻止它被输出。
我可以使用一些东西来过滤掉我的信息流中的空行吗?也许使用某种转换流?
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
removeHistoryDuplicates: true
});
rl.on("line", (line) => {
if(line.trim().length === 0) {
// don't output anything, but it is already too late because it is already written to stream :'-(
}
rl.prompt();
})
【问题讨论】: