readline.emitKeypressEvents(stream[, interface])


readline.emitKeypressEvents() 方法使给定的 可读的 流开始发出对应于接收到的输入的 'keypress' 事件。

🌐 The readline.emitKeypressEvents() method causes the given Readable stream to begin emitting 'keypress' events corresponding to received input.

可选地,interface 指定一个 readline.Interface 实例,当检测到粘贴输入时将禁用自动补全。

🌐 Optionally, interface specifies a readline.Interface instance for which autocompletion is disabled when copy-pasted input is detected.

如果 stream文字电话,那么它必须处于原始模式。

🌐 If the stream is a TTY, then it must be in raw mode.

如果 input 是终端,任何 readline 实例在其 input 上都会自动调用此方法。关闭 readline 实例不会阻止 input 发出 'keypress' 事件。

🌐 This is automatically called by any readline instance on its input if the input is a terminal. Closing the readline instance does not stop the input from emitting 'keypress' events.

readline.emitKeypressEvents(process.stdin);
if (process.stdin.isTTY)
  process.stdin.setRawMode(true);