'line' 事件


每当 input 流接收到行尾输入(\n\r\r\n)时,则会触发 'line' 事件。 这通常发生在用户按下 回车返回 时。

如果从流中读取了新数据并且该流在没有最终行尾标记的情况下结束,也会触发 'line' 事件。

使用包含单行接收输入的字符串调用监听器函数。

rl.on('line', (input) => {
  console.log(`Received: ${input}`);
});

The 'line' event is emitted whenever the input stream receives an end-of-line input (\n, \r, or \r\n). This usually occurs when the user presses Enter or Return.

The 'line' event is also emitted if new data has been read from a stream and that stream ends without a final end-of-line marker.

The listener function is called with a string containing the single line of received input.

rl.on('line', (input) => {
  console.log(`Received: ${input}`);
});