| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b2a2c6c commit 6db2562
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -349,6 +349,55 @@ async function processLineByLine() { | |||
| 349 | 349 | } | |
| 350 | 350 | ``` | |
| 351 | 351 | ||
| 352 | + ### rl.line | ||
| 353 | + <!-- YAML | ||
| 354 | + added: 0.1.98 | ||
| 355 | + --> | ||
| 356 | + | ||
| 357 | + * {string|undefined} | ||
| 358 | + | ||
| 359 | + The current input data being processed by node. | ||
| 360 | + | ||
| 361 | + This can be used when collecting input from a TTY stream to retrieve the | ||
| 362 | + current value that has been processed thus far, prior to the `line` event | ||
| 363 | + being emitted. Once the `line` event has been emitted, this property will | ||
| 364 | + be an empty string. | ||
| 365 | + | ||
| 366 | + Be aware that modifying the value during the instance runtime may have | ||
| 367 | + unintended consequences if `rl.cursor` is not also controlled. | ||
| 368 | + | ||
| 369 | + **If not using a TTY stream for input, use the [`'line'`][] event.** | ||
| 370 | + | ||
| 371 | + One possible use case would be as follows: | ||
| 372 | + | ||
| 373 | + ```js | ||
| 374 | + const values = ['lorem ipsum', 'dolor sit amet']; | ||
| 375 | + const rl = readline.createInterface(process.stdin); | ||
| 376 | + const showResults = debounce(() => { | ||
| 377 | + console.log( | ||
| 378 | + '\n', | ||
| 379 | + values.filter((val) => val.startsWith(rl.line)).join(' ') | ||
| 380 | + ); | ||
| 381 | + }, 300); | ||
| 382 | + process.stdin.on('keypress', (c, k) => { | ||
| 383 | + showResults(); | ||
| 384 | + }); | ||
| 385 | + ``` | ||
| 386 | + | ||
| 387 | + ### rl.cursor | ||
| 388 | + <!-- YAML | ||
| 389 | + added: 0.1.98 | ||
| 390 | + --> | ||
| 391 | + | ||
| 392 | + * {number|undefined} | ||
| 393 | + | ||
| 394 | + The cursor position relative to `rl.line`. | ||
| 395 | + | ||
| 396 | + This will track where the current cursor lands in the input string, when | ||
| 397 | + reading input from a TTY stream. The position of cursor determines the | ||
| 398 | + portion of the input string that will be modified as input is processed, | ||
| 399 | + as well as the column where the terminal caret will be rendered. | ||
| 400 | + | ||
| 352 | 401 | ## `readline.clearLine(stream, dir[, callback])` | |
| 353 | 402 | <!-- YAML | |
| 354 | 403 | added: v0.7.7 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments