Node.js 防止在节点readline中输出空行

Node.js 防止在节点readline中输出空行,node.js,stream,readline,Node.js,Stream,Readline,当我在键盘上按住ENTER键时,readline模块将向我的可写流输出空行(在本例中是process.stdout) 但由于我不想让空行干扰我的控制台,我想以某种方式防止它被输出 我可以用一些东西过滤掉流中的空行吗?也许使用某种类型的转换流 const readline=require(“readline”); const rl=readline.createInterface({ 输入:process.stdin, 输出:process.stdout, removeHistoryDuplica

当我在键盘上按住ENTER键时,readline模块将向我的可写流输出空行(在本例中是process.stdout)

但由于我不想让空行干扰我的控制台,我想以某种方式防止它被输出

我可以用一些东西过滤掉流中的空行吗?也许使用某种类型的转换流

const readline=require(“readline”);
const rl=readline.createInterface({
输入:process.stdin,
输出:process.stdout,
removeHistoryDuplicates:true
});
rl.on(“行”,(行)=>{
if(line.trim().length==0){
//不要输出任何内容,但已经太晚了,因为它已写入流:'-(
}
rl.prompt();
})
使用此

   readline.cursorTo(process.stdout, 0,0);
enter将自动被忽略并返回到起始位置

用这个

   readline.cursorTo(process.stdout, 0,0);
enter将自动被忽略并返回到起始位置


这行的真正含义是什么?
返回行。替换(/[^a-zA-Z]/g,”)。trim()。长度===0
只需测试是否按下enter键就可以删除所有非alpha chrsdoe似乎不起作用。好吧,在这之前它会删除所有可见的控制台输出。我使用了gif:readline.cursorTo(,0,。将行数设置为最后一行而不是0。是否可以获取最后一行?我在节点中查找了一种方法,但找不到它。:-(这一行的真正含义是什么?
返回行。替换(/[^a-zA-Z]/g,”).trim().length===0
只需测试是否按enter键即可删除所有非alpha chrsdoesn似乎不起作用。在这之前,它会删除所有可见的控制台输出。我使用gif:readline.cursorTo(,0,。将行数设置为最后一行而不是0。是否可以获取最后一行?我在node中查找了一种方法,但找不到它:-(