rl.line
节点正在处理的当前输入数据。
这可用于从 TTY 流中收集输入以检索迄今为止(在 line
事件触发之前)已处理的当前值。
一旦触发 line
事件,则此属性将是空字符串。
请注意,如果 rl.cursor
也不受控制,则在实例运行时修改该值可能会产生意想不到的后果。
如果不使用 TTY 流进行输入,则使用 'line'
事件。
一个可能的用例如下:
const values = ['lorem ipsum', 'dolor sit amet'];
const rl = readline.createInterface(process.stdin);
const showResults = debounce(() => {
console.log(
'\n',
values.filter((val) => val.startsWith(rl.line)).join(' ')
);
}, 300);
process.stdin.on('keypress', (c, k) => {
showResults();
});
The current input data being processed by node.
This can be used when collecting input from a TTY stream to retrieve the
current value that has been processed thus far, prior to the line
event
being emitted. Once the line
event has been emitted, this property will
be an empty string.
Be aware that modifying the value during the instance runtime may have
unintended consequences if rl.cursor
is not also controlled.
If not using a TTY stream for input, use the 'line'
event.
One possible use case would be as follows:
const values = ['lorem ipsum', 'dolor sit amet'];
const rl = readline.createInterface(process.stdin);
const showResults = debounce(() => {
console.log(
'\n',
values.filter((val) => val.startsWith(rl.line)).join(' ')
);
}, 300);
process.stdin.on('keypress', (c, k) => {
showResults();
});