11cb0ef41Sopenharmony_ci# Readline 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci<!--introduced_in=v0.10.0--> 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci> Stability: 2 - Stable 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci<!-- source_link=lib/readline.js --> 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciThe `node:readline` module provides an interface for reading data from a 101cb0ef41Sopenharmony_ci[Readable][] stream (such as [`process.stdin`][]) one line at a time. 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciTo use the promise-based APIs: 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci```mjs 151cb0ef41Sopenharmony_ciimport * as readline from 'node:readline/promises'; 161cb0ef41Sopenharmony_ci``` 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci```cjs 191cb0ef41Sopenharmony_ciconst readline = require('node:readline/promises'); 201cb0ef41Sopenharmony_ci``` 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciTo use the callback and sync APIs: 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci```mjs 251cb0ef41Sopenharmony_ciimport * as readline from 'node:readline'; 261cb0ef41Sopenharmony_ci``` 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci```cjs 291cb0ef41Sopenharmony_ciconst readline = require('node:readline'); 301cb0ef41Sopenharmony_ci``` 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ciThe following simple example illustrates the basic use of the `node:readline` 331cb0ef41Sopenharmony_cimodule. 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci```mjs 361cb0ef41Sopenharmony_ciimport * as readline from 'node:readline/promises'; 371cb0ef41Sopenharmony_ciimport { stdin as input, stdout as output } from 'node:process'; 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ciconst rl = readline.createInterface({ input, output }); 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ciconst answer = await rl.question('What do you think of Node.js? '); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ciconsole.log(`Thank you for your valuable feedback: ${answer}`); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_cirl.close(); 461cb0ef41Sopenharmony_ci``` 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci```cjs 491cb0ef41Sopenharmony_ciconst readline = require('node:readline'); 501cb0ef41Sopenharmony_ciconst { stdin: input, stdout: output } = require('node:process'); 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ciconst rl = readline.createInterface({ input, output }); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_cirl.question('What do you think of Node.js? ', (answer) => { 551cb0ef41Sopenharmony_ci // TODO: Log the answer in a database 561cb0ef41Sopenharmony_ci console.log(`Thank you for your valuable feedback: ${answer}`); 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci rl.close(); 591cb0ef41Sopenharmony_ci}); 601cb0ef41Sopenharmony_ci``` 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ciOnce this code is invoked, the Node.js application will not terminate until the 631cb0ef41Sopenharmony_ci`readline.Interface` is closed because the interface waits for data to be 641cb0ef41Sopenharmony_cireceived on the `input` stream. 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci<a id='readline_class_interface'></a> 671cb0ef41Sopenharmony_ci 681cb0ef41Sopenharmony_ci## Class: `InterfaceConstructor` 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci<!-- YAML 711cb0ef41Sopenharmony_ciadded: v0.1.104 721cb0ef41Sopenharmony_ci--> 731cb0ef41Sopenharmony_ci 741cb0ef41Sopenharmony_ci* Extends: {EventEmitter} 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ciInstances of the `InterfaceConstructor` class are constructed using the 771cb0ef41Sopenharmony_ci`readlinePromises.createInterface()` or `readline.createInterface()` method. 781cb0ef41Sopenharmony_ciEvery instance is associated with a single `input` [Readable][] stream and a 791cb0ef41Sopenharmony_cisingle `output` [Writable][] stream. 801cb0ef41Sopenharmony_ciThe `output` stream is used to print prompts for user input that arrives on, 811cb0ef41Sopenharmony_ciand is read from, the `input` stream. 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci### Event: `'close'` 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci<!-- YAML 861cb0ef41Sopenharmony_ciadded: v0.1.98 871cb0ef41Sopenharmony_ci--> 881cb0ef41Sopenharmony_ci 891cb0ef41Sopenharmony_ciThe `'close'` event is emitted when one of the following occur: 901cb0ef41Sopenharmony_ci 911cb0ef41Sopenharmony_ci* The `rl.close()` method is called and the `InterfaceConstructor` instance has 921cb0ef41Sopenharmony_ci relinquished control over the `input` and `output` streams; 931cb0ef41Sopenharmony_ci* The `input` stream receives its `'end'` event; 941cb0ef41Sopenharmony_ci* The `input` stream receives <kbd>Ctrl</kbd>+<kbd>D</kbd> to signal 951cb0ef41Sopenharmony_ci end-of-transmission (EOT); 961cb0ef41Sopenharmony_ci* The `input` stream receives <kbd>Ctrl</kbd>+<kbd>C</kbd> to signal `SIGINT` 971cb0ef41Sopenharmony_ci and there is no `'SIGINT'` event listener registered on the 981cb0ef41Sopenharmony_ci `InterfaceConstructor` instance. 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ciThe listener function is called without passing any arguments. 1011cb0ef41Sopenharmony_ci 1021cb0ef41Sopenharmony_ciThe `InterfaceConstructor` instance is finished once the `'close'` event is 1031cb0ef41Sopenharmony_ciemitted. 1041cb0ef41Sopenharmony_ci 1051cb0ef41Sopenharmony_ci### Event: `'line'` 1061cb0ef41Sopenharmony_ci 1071cb0ef41Sopenharmony_ci<!-- YAML 1081cb0ef41Sopenharmony_ciadded: v0.1.98 1091cb0ef41Sopenharmony_ci--> 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ciThe `'line'` event is emitted whenever the `input` stream receives an 1121cb0ef41Sopenharmony_ciend-of-line input (`\n`, `\r`, or `\r\n`). This usually occurs when the user 1131cb0ef41Sopenharmony_cipresses <kbd>Enter</kbd> or <kbd>Return</kbd>. 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ciThe `'line'` event is also emitted if new data has been read from a stream and 1161cb0ef41Sopenharmony_cithat stream ends without a final end-of-line marker. 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_ciThe listener function is called with a string containing the single line of 1191cb0ef41Sopenharmony_cireceived input. 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_ci```js 1221cb0ef41Sopenharmony_cirl.on('line', (input) => { 1231cb0ef41Sopenharmony_ci console.log(`Received: ${input}`); 1241cb0ef41Sopenharmony_ci}); 1251cb0ef41Sopenharmony_ci``` 1261cb0ef41Sopenharmony_ci 1271cb0ef41Sopenharmony_ci### Event: `'history'` 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_ci<!-- YAML 1301cb0ef41Sopenharmony_ciadded: 1311cb0ef41Sopenharmony_ci - v15.8.0 1321cb0ef41Sopenharmony_ci - v14.18.0 1331cb0ef41Sopenharmony_ci--> 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ciThe `'history'` event is emitted whenever the history array has changed. 1361cb0ef41Sopenharmony_ci 1371cb0ef41Sopenharmony_ciThe listener function is called with an array containing the history array. 1381cb0ef41Sopenharmony_ciIt will reflect all changes, added lines and removed lines due to 1391cb0ef41Sopenharmony_ci`historySize` and `removeHistoryDuplicates`. 1401cb0ef41Sopenharmony_ci 1411cb0ef41Sopenharmony_ciThe primary purpose is to allow a listener to persist the history. 1421cb0ef41Sopenharmony_ciIt is also possible for the listener to change the history object. This 1431cb0ef41Sopenharmony_cicould be useful to prevent certain lines to be added to the history, like 1441cb0ef41Sopenharmony_cia password. 1451cb0ef41Sopenharmony_ci 1461cb0ef41Sopenharmony_ci```js 1471cb0ef41Sopenharmony_cirl.on('history', (history) => { 1481cb0ef41Sopenharmony_ci console.log(`Received: ${history}`); 1491cb0ef41Sopenharmony_ci}); 1501cb0ef41Sopenharmony_ci``` 1511cb0ef41Sopenharmony_ci 1521cb0ef41Sopenharmony_ci### Event: `'pause'` 1531cb0ef41Sopenharmony_ci 1541cb0ef41Sopenharmony_ci<!-- YAML 1551cb0ef41Sopenharmony_ciadded: v0.7.5 1561cb0ef41Sopenharmony_ci--> 1571cb0ef41Sopenharmony_ci 1581cb0ef41Sopenharmony_ciThe `'pause'` event is emitted when one of the following occur: 1591cb0ef41Sopenharmony_ci 1601cb0ef41Sopenharmony_ci* The `input` stream is paused. 1611cb0ef41Sopenharmony_ci* The `input` stream is not paused and receives the `'SIGCONT'` event. (See 1621cb0ef41Sopenharmony_ci events [`'SIGTSTP'`][] and [`'SIGCONT'`][].) 1631cb0ef41Sopenharmony_ci 1641cb0ef41Sopenharmony_ciThe listener function is called without passing any arguments. 1651cb0ef41Sopenharmony_ci 1661cb0ef41Sopenharmony_ci```js 1671cb0ef41Sopenharmony_cirl.on('pause', () => { 1681cb0ef41Sopenharmony_ci console.log('Readline paused.'); 1691cb0ef41Sopenharmony_ci}); 1701cb0ef41Sopenharmony_ci``` 1711cb0ef41Sopenharmony_ci 1721cb0ef41Sopenharmony_ci### Event: `'resume'` 1731cb0ef41Sopenharmony_ci 1741cb0ef41Sopenharmony_ci<!-- YAML 1751cb0ef41Sopenharmony_ciadded: v0.7.5 1761cb0ef41Sopenharmony_ci--> 1771cb0ef41Sopenharmony_ci 1781cb0ef41Sopenharmony_ciThe `'resume'` event is emitted whenever the `input` stream is resumed. 1791cb0ef41Sopenharmony_ci 1801cb0ef41Sopenharmony_ciThe listener function is called without passing any arguments. 1811cb0ef41Sopenharmony_ci 1821cb0ef41Sopenharmony_ci```js 1831cb0ef41Sopenharmony_cirl.on('resume', () => { 1841cb0ef41Sopenharmony_ci console.log('Readline resumed.'); 1851cb0ef41Sopenharmony_ci}); 1861cb0ef41Sopenharmony_ci``` 1871cb0ef41Sopenharmony_ci 1881cb0ef41Sopenharmony_ci### Event: `'SIGCONT'` 1891cb0ef41Sopenharmony_ci 1901cb0ef41Sopenharmony_ci<!-- YAML 1911cb0ef41Sopenharmony_ciadded: v0.7.5 1921cb0ef41Sopenharmony_ci--> 1931cb0ef41Sopenharmony_ci 1941cb0ef41Sopenharmony_ciThe `'SIGCONT'` event is emitted when a Node.js process previously moved into 1951cb0ef41Sopenharmony_cithe background using <kbd>Ctrl</kbd>+<kbd>Z</kbd> (i.e. `SIGTSTP`) is then 1961cb0ef41Sopenharmony_cibrought back to the foreground using fg(1p). 1971cb0ef41Sopenharmony_ci 1981cb0ef41Sopenharmony_ciIf the `input` stream was paused _before_ the `SIGTSTP` request, this event will 1991cb0ef41Sopenharmony_cinot be emitted. 2001cb0ef41Sopenharmony_ci 2011cb0ef41Sopenharmony_ciThe listener function is invoked without passing any arguments. 2021cb0ef41Sopenharmony_ci 2031cb0ef41Sopenharmony_ci```js 2041cb0ef41Sopenharmony_cirl.on('SIGCONT', () => { 2051cb0ef41Sopenharmony_ci // `prompt` will automatically resume the stream 2061cb0ef41Sopenharmony_ci rl.prompt(); 2071cb0ef41Sopenharmony_ci}); 2081cb0ef41Sopenharmony_ci``` 2091cb0ef41Sopenharmony_ci 2101cb0ef41Sopenharmony_ciThe `'SIGCONT'` event is _not_ supported on Windows. 2111cb0ef41Sopenharmony_ci 2121cb0ef41Sopenharmony_ci### Event: `'SIGINT'` 2131cb0ef41Sopenharmony_ci 2141cb0ef41Sopenharmony_ci<!-- YAML 2151cb0ef41Sopenharmony_ciadded: v0.3.0 2161cb0ef41Sopenharmony_ci--> 2171cb0ef41Sopenharmony_ci 2181cb0ef41Sopenharmony_ciThe `'SIGINT'` event is emitted whenever the `input` stream receives 2191cb0ef41Sopenharmony_cia <kbd>Ctrl+C</kbd> input, known typically as `SIGINT`. If there are no 2201cb0ef41Sopenharmony_ci`'SIGINT'` event listeners registered when the `input` stream receives a 2211cb0ef41Sopenharmony_ci`SIGINT`, the `'pause'` event will be emitted. 2221cb0ef41Sopenharmony_ci 2231cb0ef41Sopenharmony_ciThe listener function is invoked without passing any arguments. 2241cb0ef41Sopenharmony_ci 2251cb0ef41Sopenharmony_ci```js 2261cb0ef41Sopenharmony_cirl.on('SIGINT', () => { 2271cb0ef41Sopenharmony_ci rl.question('Are you sure you want to exit? ', (answer) => { 2281cb0ef41Sopenharmony_ci if (answer.match(/^y(es)?$/i)) rl.pause(); 2291cb0ef41Sopenharmony_ci }); 2301cb0ef41Sopenharmony_ci}); 2311cb0ef41Sopenharmony_ci``` 2321cb0ef41Sopenharmony_ci 2331cb0ef41Sopenharmony_ci### Event: `'SIGTSTP'` 2341cb0ef41Sopenharmony_ci 2351cb0ef41Sopenharmony_ci<!-- YAML 2361cb0ef41Sopenharmony_ciadded: v0.7.5 2371cb0ef41Sopenharmony_ci--> 2381cb0ef41Sopenharmony_ci 2391cb0ef41Sopenharmony_ciThe `'SIGTSTP'` event is emitted when the `input` stream receives 2401cb0ef41Sopenharmony_cia <kbd>Ctrl</kbd>+<kbd>Z</kbd> input, typically known as `SIGTSTP`. If there are 2411cb0ef41Sopenharmony_cino `'SIGTSTP'` event listeners registered when the `input` stream receives a 2421cb0ef41Sopenharmony_ci`SIGTSTP`, the Node.js process will be sent to the background. 2431cb0ef41Sopenharmony_ci 2441cb0ef41Sopenharmony_ciWhen the program is resumed using fg(1p), the `'pause'` and `'SIGCONT'` events 2451cb0ef41Sopenharmony_ciwill be emitted. These can be used to resume the `input` stream. 2461cb0ef41Sopenharmony_ci 2471cb0ef41Sopenharmony_ciThe `'pause'` and `'SIGCONT'` events will not be emitted if the `input` was 2481cb0ef41Sopenharmony_cipaused before the process was sent to the background. 2491cb0ef41Sopenharmony_ci 2501cb0ef41Sopenharmony_ciThe listener function is invoked without passing any arguments. 2511cb0ef41Sopenharmony_ci 2521cb0ef41Sopenharmony_ci```js 2531cb0ef41Sopenharmony_cirl.on('SIGTSTP', () => { 2541cb0ef41Sopenharmony_ci // This will override SIGTSTP and prevent the program from going to the 2551cb0ef41Sopenharmony_ci // background. 2561cb0ef41Sopenharmony_ci console.log('Caught SIGTSTP.'); 2571cb0ef41Sopenharmony_ci}); 2581cb0ef41Sopenharmony_ci``` 2591cb0ef41Sopenharmony_ci 2601cb0ef41Sopenharmony_ciThe `'SIGTSTP'` event is _not_ supported on Windows. 2611cb0ef41Sopenharmony_ci 2621cb0ef41Sopenharmony_ci### `rl.close()` 2631cb0ef41Sopenharmony_ci 2641cb0ef41Sopenharmony_ci<!-- YAML 2651cb0ef41Sopenharmony_ciadded: v0.1.98 2661cb0ef41Sopenharmony_ci--> 2671cb0ef41Sopenharmony_ci 2681cb0ef41Sopenharmony_ciThe `rl.close()` method closes the `InterfaceConstructor` instance and 2691cb0ef41Sopenharmony_cirelinquishes control over the `input` and `output` streams. When called, 2701cb0ef41Sopenharmony_cithe `'close'` event will be emitted. 2711cb0ef41Sopenharmony_ci 2721cb0ef41Sopenharmony_ciCalling `rl.close()` does not immediately stop other events (including `'line'`) 2731cb0ef41Sopenharmony_cifrom being emitted by the `InterfaceConstructor` instance. 2741cb0ef41Sopenharmony_ci 2751cb0ef41Sopenharmony_ci### `rl.pause()` 2761cb0ef41Sopenharmony_ci 2771cb0ef41Sopenharmony_ci<!-- YAML 2781cb0ef41Sopenharmony_ciadded: v0.3.4 2791cb0ef41Sopenharmony_ci--> 2801cb0ef41Sopenharmony_ci 2811cb0ef41Sopenharmony_ciThe `rl.pause()` method pauses the `input` stream, allowing it to be resumed 2821cb0ef41Sopenharmony_cilater if necessary. 2831cb0ef41Sopenharmony_ci 2841cb0ef41Sopenharmony_ciCalling `rl.pause()` does not immediately pause other events (including 2851cb0ef41Sopenharmony_ci`'line'`) from being emitted by the `InterfaceConstructor` instance. 2861cb0ef41Sopenharmony_ci 2871cb0ef41Sopenharmony_ci### `rl.prompt([preserveCursor])` 2881cb0ef41Sopenharmony_ci 2891cb0ef41Sopenharmony_ci<!-- YAML 2901cb0ef41Sopenharmony_ciadded: v0.1.98 2911cb0ef41Sopenharmony_ci--> 2921cb0ef41Sopenharmony_ci 2931cb0ef41Sopenharmony_ci* `preserveCursor` {boolean} If `true`, prevents the cursor placement from 2941cb0ef41Sopenharmony_ci being reset to `0`. 2951cb0ef41Sopenharmony_ci 2961cb0ef41Sopenharmony_ciThe `rl.prompt()` method writes the `InterfaceConstructor` instances configured 2971cb0ef41Sopenharmony_ci`prompt` to a new line in `output` in order to provide a user with a new 2981cb0ef41Sopenharmony_cilocation at which to provide input. 2991cb0ef41Sopenharmony_ci 3001cb0ef41Sopenharmony_ciWhen called, `rl.prompt()` will resume the `input` stream if it has been 3011cb0ef41Sopenharmony_cipaused. 3021cb0ef41Sopenharmony_ci 3031cb0ef41Sopenharmony_ciIf the `InterfaceConstructor` was created with `output` set to `null` or 3041cb0ef41Sopenharmony_ci`undefined` the prompt is not written. 3051cb0ef41Sopenharmony_ci 3061cb0ef41Sopenharmony_ci### `rl.question(query[, options], callback)` 3071cb0ef41Sopenharmony_ci 3081cb0ef41Sopenharmony_ci<!-- YAML 3091cb0ef41Sopenharmony_ciadded: v0.3.3 3101cb0ef41Sopenharmony_ci--> 3111cb0ef41Sopenharmony_ci 3121cb0ef41Sopenharmony_ci* `query` {string} A statement or query to write to `output`, prepended to the 3131cb0ef41Sopenharmony_ci prompt. 3141cb0ef41Sopenharmony_ci* `options` {Object} 3151cb0ef41Sopenharmony_ci * `signal` {AbortSignal} Optionally allows the `question()` to be canceled 3161cb0ef41Sopenharmony_ci using an `AbortController`. 3171cb0ef41Sopenharmony_ci* `callback` {Function} A callback function that is invoked with the user's 3181cb0ef41Sopenharmony_ci input in response to the `query`. 3191cb0ef41Sopenharmony_ci 3201cb0ef41Sopenharmony_ciThe `rl.question()` method displays the `query` by writing it to the `output`, 3211cb0ef41Sopenharmony_ciwaits for user input to be provided on `input`, then invokes the `callback` 3221cb0ef41Sopenharmony_cifunction passing the provided input as the first argument. 3231cb0ef41Sopenharmony_ci 3241cb0ef41Sopenharmony_ciWhen called, `rl.question()` will resume the `input` stream if it has been 3251cb0ef41Sopenharmony_cipaused. 3261cb0ef41Sopenharmony_ci 3271cb0ef41Sopenharmony_ciIf the `InterfaceConstructor` was created with `output` set to `null` or 3281cb0ef41Sopenharmony_ci`undefined` the `query` is not written. 3291cb0ef41Sopenharmony_ci 3301cb0ef41Sopenharmony_ciThe `callback` function passed to `rl.question()` does not follow the typical 3311cb0ef41Sopenharmony_cipattern of accepting an `Error` object or `null` as the first argument. 3321cb0ef41Sopenharmony_ciThe `callback` is called with the provided answer as the only argument. 3331cb0ef41Sopenharmony_ci 3341cb0ef41Sopenharmony_ciAn error will be thrown if calling `rl.question()` after `rl.close()`. 3351cb0ef41Sopenharmony_ci 3361cb0ef41Sopenharmony_ciExample usage: 3371cb0ef41Sopenharmony_ci 3381cb0ef41Sopenharmony_ci```js 3391cb0ef41Sopenharmony_cirl.question('What is your favorite food? ', (answer) => { 3401cb0ef41Sopenharmony_ci console.log(`Oh, so your favorite food is ${answer}`); 3411cb0ef41Sopenharmony_ci}); 3421cb0ef41Sopenharmony_ci``` 3431cb0ef41Sopenharmony_ci 3441cb0ef41Sopenharmony_ciUsing an `AbortController` to cancel a question. 3451cb0ef41Sopenharmony_ci 3461cb0ef41Sopenharmony_ci```js 3471cb0ef41Sopenharmony_ciconst ac = new AbortController(); 3481cb0ef41Sopenharmony_ciconst signal = ac.signal; 3491cb0ef41Sopenharmony_ci 3501cb0ef41Sopenharmony_cirl.question('What is your favorite food? ', { signal }, (answer) => { 3511cb0ef41Sopenharmony_ci console.log(`Oh, so your favorite food is ${answer}`); 3521cb0ef41Sopenharmony_ci}); 3531cb0ef41Sopenharmony_ci 3541cb0ef41Sopenharmony_cisignal.addEventListener('abort', () => { 3551cb0ef41Sopenharmony_ci console.log('The food question timed out'); 3561cb0ef41Sopenharmony_ci}, { once: true }); 3571cb0ef41Sopenharmony_ci 3581cb0ef41Sopenharmony_cisetTimeout(() => ac.abort(), 10000); 3591cb0ef41Sopenharmony_ci``` 3601cb0ef41Sopenharmony_ci 3611cb0ef41Sopenharmony_ci### `rl.resume()` 3621cb0ef41Sopenharmony_ci 3631cb0ef41Sopenharmony_ci<!-- YAML 3641cb0ef41Sopenharmony_ciadded: v0.3.4 3651cb0ef41Sopenharmony_ci--> 3661cb0ef41Sopenharmony_ci 3671cb0ef41Sopenharmony_ciThe `rl.resume()` method resumes the `input` stream if it has been paused. 3681cb0ef41Sopenharmony_ci 3691cb0ef41Sopenharmony_ci### `rl.setPrompt(prompt)` 3701cb0ef41Sopenharmony_ci 3711cb0ef41Sopenharmony_ci<!-- YAML 3721cb0ef41Sopenharmony_ciadded: v0.1.98 3731cb0ef41Sopenharmony_ci--> 3741cb0ef41Sopenharmony_ci 3751cb0ef41Sopenharmony_ci* `prompt` {string} 3761cb0ef41Sopenharmony_ci 3771cb0ef41Sopenharmony_ciThe `rl.setPrompt()` method sets the prompt that will be written to `output` 3781cb0ef41Sopenharmony_ciwhenever `rl.prompt()` is called. 3791cb0ef41Sopenharmony_ci 3801cb0ef41Sopenharmony_ci### `rl.getPrompt()` 3811cb0ef41Sopenharmony_ci 3821cb0ef41Sopenharmony_ci<!-- YAML 3831cb0ef41Sopenharmony_ciadded: 3841cb0ef41Sopenharmony_ci - v15.3.0 3851cb0ef41Sopenharmony_ci - v14.17.0 3861cb0ef41Sopenharmony_ci--> 3871cb0ef41Sopenharmony_ci 3881cb0ef41Sopenharmony_ci* Returns: {string} the current prompt string 3891cb0ef41Sopenharmony_ci 3901cb0ef41Sopenharmony_ciThe `rl.getPrompt()` method returns the current prompt used by `rl.prompt()`. 3911cb0ef41Sopenharmony_ci 3921cb0ef41Sopenharmony_ci### `rl.write(data[, key])` 3931cb0ef41Sopenharmony_ci 3941cb0ef41Sopenharmony_ci<!-- YAML 3951cb0ef41Sopenharmony_ciadded: v0.1.98 3961cb0ef41Sopenharmony_ci--> 3971cb0ef41Sopenharmony_ci 3981cb0ef41Sopenharmony_ci* `data` {string} 3991cb0ef41Sopenharmony_ci* `key` {Object} 4001cb0ef41Sopenharmony_ci * `ctrl` {boolean} `true` to indicate the <kbd>Ctrl</kbd> key. 4011cb0ef41Sopenharmony_ci * `meta` {boolean} `true` to indicate the <kbd>Meta</kbd> key. 4021cb0ef41Sopenharmony_ci * `shift` {boolean} `true` to indicate the <kbd>Shift</kbd> key. 4031cb0ef41Sopenharmony_ci * `name` {string} The name of the a key. 4041cb0ef41Sopenharmony_ci 4051cb0ef41Sopenharmony_ciThe `rl.write()` method will write either `data` or a key sequence identified 4061cb0ef41Sopenharmony_ciby `key` to the `output`. The `key` argument is supported only if `output` is 4071cb0ef41Sopenharmony_cia [TTY][] text terminal. See [TTY keybindings][] for a list of key 4081cb0ef41Sopenharmony_cicombinations. 4091cb0ef41Sopenharmony_ci 4101cb0ef41Sopenharmony_ciIf `key` is specified, `data` is ignored. 4111cb0ef41Sopenharmony_ci 4121cb0ef41Sopenharmony_ciWhen called, `rl.write()` will resume the `input` stream if it has been 4131cb0ef41Sopenharmony_cipaused. 4141cb0ef41Sopenharmony_ci 4151cb0ef41Sopenharmony_ciIf the `InterfaceConstructor` was created with `output` set to `null` or 4161cb0ef41Sopenharmony_ci`undefined` the `data` and `key` are not written. 4171cb0ef41Sopenharmony_ci 4181cb0ef41Sopenharmony_ci```js 4191cb0ef41Sopenharmony_cirl.write('Delete this!'); 4201cb0ef41Sopenharmony_ci// Simulate Ctrl+U to delete the line written previously 4211cb0ef41Sopenharmony_cirl.write(null, { ctrl: true, name: 'u' }); 4221cb0ef41Sopenharmony_ci``` 4231cb0ef41Sopenharmony_ci 4241cb0ef41Sopenharmony_ciThe `rl.write()` method will write the data to the `readline` `Interface`'s 4251cb0ef41Sopenharmony_ci`input` _as if it were provided by the user_. 4261cb0ef41Sopenharmony_ci 4271cb0ef41Sopenharmony_ci### `rl[Symbol.asyncIterator]()` 4281cb0ef41Sopenharmony_ci 4291cb0ef41Sopenharmony_ci<!-- YAML 4301cb0ef41Sopenharmony_ciadded: 4311cb0ef41Sopenharmony_ci - v11.4.0 4321cb0ef41Sopenharmony_ci - v10.16.0 4331cb0ef41Sopenharmony_cichanges: 4341cb0ef41Sopenharmony_ci - version: 4351cb0ef41Sopenharmony_ci - v11.14.0 4361cb0ef41Sopenharmony_ci - v10.17.0 4371cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/26989 4381cb0ef41Sopenharmony_ci description: Symbol.asyncIterator support is no longer experimental. 4391cb0ef41Sopenharmony_ci--> 4401cb0ef41Sopenharmony_ci 4411cb0ef41Sopenharmony_ci* Returns: {AsyncIterator} 4421cb0ef41Sopenharmony_ci 4431cb0ef41Sopenharmony_ciCreate an `AsyncIterator` object that iterates through each line in the input 4441cb0ef41Sopenharmony_cistream as a string. This method allows asynchronous iteration of 4451cb0ef41Sopenharmony_ci`InterfaceConstructor` objects through `for await...of` loops. 4461cb0ef41Sopenharmony_ci 4471cb0ef41Sopenharmony_ciErrors in the input stream are not forwarded. 4481cb0ef41Sopenharmony_ci 4491cb0ef41Sopenharmony_ciIf the loop is terminated with `break`, `throw`, or `return`, 4501cb0ef41Sopenharmony_ci[`rl.close()`][] will be called. In other words, iterating over a 4511cb0ef41Sopenharmony_ci`InterfaceConstructor` will always consume the input stream fully. 4521cb0ef41Sopenharmony_ci 4531cb0ef41Sopenharmony_ciPerformance is not on par with the traditional `'line'` event API. Use `'line'` 4541cb0ef41Sopenharmony_ciinstead for performance-sensitive applications. 4551cb0ef41Sopenharmony_ci 4561cb0ef41Sopenharmony_ci```js 4571cb0ef41Sopenharmony_ciasync function processLineByLine() { 4581cb0ef41Sopenharmony_ci const rl = readline.createInterface({ 4591cb0ef41Sopenharmony_ci // ... 4601cb0ef41Sopenharmony_ci }); 4611cb0ef41Sopenharmony_ci 4621cb0ef41Sopenharmony_ci for await (const line of rl) { 4631cb0ef41Sopenharmony_ci // Each line in the readline input will be successively available here as 4641cb0ef41Sopenharmony_ci // `line`. 4651cb0ef41Sopenharmony_ci } 4661cb0ef41Sopenharmony_ci} 4671cb0ef41Sopenharmony_ci``` 4681cb0ef41Sopenharmony_ci 4691cb0ef41Sopenharmony_ci`readline.createInterface()` will start to consume the input stream once 4701cb0ef41Sopenharmony_ciinvoked. Having asynchronous operations between interface creation and 4711cb0ef41Sopenharmony_ciasynchronous iteration may result in missed lines. 4721cb0ef41Sopenharmony_ci 4731cb0ef41Sopenharmony_ci### `rl.line` 4741cb0ef41Sopenharmony_ci 4751cb0ef41Sopenharmony_ci<!-- YAML 4761cb0ef41Sopenharmony_ciadded: v0.1.98 4771cb0ef41Sopenharmony_cichanges: 4781cb0ef41Sopenharmony_ci - version: 4791cb0ef41Sopenharmony_ci - v15.8.0 4801cb0ef41Sopenharmony_ci - v14.18.0 4811cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/33676 4821cb0ef41Sopenharmony_ci description: Value will always be a string, never undefined. 4831cb0ef41Sopenharmony_ci--> 4841cb0ef41Sopenharmony_ci 4851cb0ef41Sopenharmony_ci* {string} 4861cb0ef41Sopenharmony_ci 4871cb0ef41Sopenharmony_ciThe current input data being processed by node. 4881cb0ef41Sopenharmony_ci 4891cb0ef41Sopenharmony_ciThis can be used when collecting input from a TTY stream to retrieve the 4901cb0ef41Sopenharmony_cicurrent value that has been processed thus far, prior to the `line` event 4911cb0ef41Sopenharmony_cibeing emitted. Once the `line` event has been emitted, this property will 4921cb0ef41Sopenharmony_cibe an empty string. 4931cb0ef41Sopenharmony_ci 4941cb0ef41Sopenharmony_ciBe aware that modifying the value during the instance runtime may have 4951cb0ef41Sopenharmony_ciunintended consequences if `rl.cursor` is not also controlled. 4961cb0ef41Sopenharmony_ci 4971cb0ef41Sopenharmony_ci**If not using a TTY stream for input, use the [`'line'`][] event.** 4981cb0ef41Sopenharmony_ci 4991cb0ef41Sopenharmony_ciOne possible use case would be as follows: 5001cb0ef41Sopenharmony_ci 5011cb0ef41Sopenharmony_ci```js 5021cb0ef41Sopenharmony_ciconst values = ['lorem ipsum', 'dolor sit amet']; 5031cb0ef41Sopenharmony_ciconst rl = readline.createInterface(process.stdin); 5041cb0ef41Sopenharmony_ciconst showResults = debounce(() => { 5051cb0ef41Sopenharmony_ci console.log( 5061cb0ef41Sopenharmony_ci '\n', 5071cb0ef41Sopenharmony_ci values.filter((val) => val.startsWith(rl.line)).join(' '), 5081cb0ef41Sopenharmony_ci ); 5091cb0ef41Sopenharmony_ci}, 300); 5101cb0ef41Sopenharmony_ciprocess.stdin.on('keypress', (c, k) => { 5111cb0ef41Sopenharmony_ci showResults(); 5121cb0ef41Sopenharmony_ci}); 5131cb0ef41Sopenharmony_ci``` 5141cb0ef41Sopenharmony_ci 5151cb0ef41Sopenharmony_ci### `rl.cursor` 5161cb0ef41Sopenharmony_ci 5171cb0ef41Sopenharmony_ci<!-- YAML 5181cb0ef41Sopenharmony_ciadded: v0.1.98 5191cb0ef41Sopenharmony_ci--> 5201cb0ef41Sopenharmony_ci 5211cb0ef41Sopenharmony_ci* {number|undefined} 5221cb0ef41Sopenharmony_ci 5231cb0ef41Sopenharmony_ciThe cursor position relative to `rl.line`. 5241cb0ef41Sopenharmony_ci 5251cb0ef41Sopenharmony_ciThis will track where the current cursor lands in the input string, when 5261cb0ef41Sopenharmony_cireading input from a TTY stream. The position of cursor determines the 5271cb0ef41Sopenharmony_ciportion of the input string that will be modified as input is processed, 5281cb0ef41Sopenharmony_cias well as the column where the terminal caret will be rendered. 5291cb0ef41Sopenharmony_ci 5301cb0ef41Sopenharmony_ci### `rl.getCursorPos()` 5311cb0ef41Sopenharmony_ci 5321cb0ef41Sopenharmony_ci<!-- YAML 5331cb0ef41Sopenharmony_ciadded: 5341cb0ef41Sopenharmony_ci - v13.5.0 5351cb0ef41Sopenharmony_ci - v12.16.0 5361cb0ef41Sopenharmony_ci--> 5371cb0ef41Sopenharmony_ci 5381cb0ef41Sopenharmony_ci* Returns: {Object} 5391cb0ef41Sopenharmony_ci * `rows` {number} the row of the prompt the cursor currently lands on 5401cb0ef41Sopenharmony_ci * `cols` {number} the screen column the cursor currently lands on 5411cb0ef41Sopenharmony_ci 5421cb0ef41Sopenharmony_ciReturns the real position of the cursor in relation to the input 5431cb0ef41Sopenharmony_ciprompt + string. Long input (wrapping) strings, as well as multiple 5441cb0ef41Sopenharmony_ciline prompts are included in the calculations. 5451cb0ef41Sopenharmony_ci 5461cb0ef41Sopenharmony_ci## Promises API 5471cb0ef41Sopenharmony_ci 5481cb0ef41Sopenharmony_ci<!-- YAML 5491cb0ef41Sopenharmony_ciadded: v17.0.0 5501cb0ef41Sopenharmony_ci--> 5511cb0ef41Sopenharmony_ci 5521cb0ef41Sopenharmony_ci> Stability: 1 - Experimental 5531cb0ef41Sopenharmony_ci 5541cb0ef41Sopenharmony_ci### Class: `readlinePromises.Interface` 5551cb0ef41Sopenharmony_ci 5561cb0ef41Sopenharmony_ci<!-- YAML 5571cb0ef41Sopenharmony_ciadded: v17.0.0 5581cb0ef41Sopenharmony_ci--> 5591cb0ef41Sopenharmony_ci 5601cb0ef41Sopenharmony_ci* Extends: {readline.InterfaceConstructor} 5611cb0ef41Sopenharmony_ci 5621cb0ef41Sopenharmony_ciInstances of the `readlinePromises.Interface` class are constructed using the 5631cb0ef41Sopenharmony_ci`readlinePromises.createInterface()` method. Every instance is associated with a 5641cb0ef41Sopenharmony_cisingle `input` [Readable][] stream and a single `output` [Writable][] stream. 5651cb0ef41Sopenharmony_ciThe `output` stream is used to print prompts for user input that arrives on, 5661cb0ef41Sopenharmony_ciand is read from, the `input` stream. 5671cb0ef41Sopenharmony_ci 5681cb0ef41Sopenharmony_ci#### `rl.question(query[, options])` 5691cb0ef41Sopenharmony_ci 5701cb0ef41Sopenharmony_ci<!-- YAML 5711cb0ef41Sopenharmony_ciadded: v17.0.0 5721cb0ef41Sopenharmony_ci--> 5731cb0ef41Sopenharmony_ci 5741cb0ef41Sopenharmony_ci* `query` {string} A statement or query to write to `output`, prepended to the 5751cb0ef41Sopenharmony_ci prompt. 5761cb0ef41Sopenharmony_ci* `options` {Object} 5771cb0ef41Sopenharmony_ci * `signal` {AbortSignal} Optionally allows the `question()` to be canceled 5781cb0ef41Sopenharmony_ci using an `AbortSignal`. 5791cb0ef41Sopenharmony_ci* Returns: {Promise} A promise that is fulfilled with the user's 5801cb0ef41Sopenharmony_ci input in response to the `query`. 5811cb0ef41Sopenharmony_ci 5821cb0ef41Sopenharmony_ciThe `rl.question()` method displays the `query` by writing it to the `output`, 5831cb0ef41Sopenharmony_ciwaits for user input to be provided on `input`, then invokes the `callback` 5841cb0ef41Sopenharmony_cifunction passing the provided input as the first argument. 5851cb0ef41Sopenharmony_ci 5861cb0ef41Sopenharmony_ciWhen called, `rl.question()` will resume the `input` stream if it has been 5871cb0ef41Sopenharmony_cipaused. 5881cb0ef41Sopenharmony_ci 5891cb0ef41Sopenharmony_ciIf the `readlinePromises.Interface` was created with `output` set to `null` or 5901cb0ef41Sopenharmony_ci`undefined` the `query` is not written. 5911cb0ef41Sopenharmony_ci 5921cb0ef41Sopenharmony_ciIf the question is called after `rl.close()`, it returns a rejected promise. 5931cb0ef41Sopenharmony_ci 5941cb0ef41Sopenharmony_ciExample usage: 5951cb0ef41Sopenharmony_ci 5961cb0ef41Sopenharmony_ci```mjs 5971cb0ef41Sopenharmony_ciconst answer = await rl.question('What is your favorite food? '); 5981cb0ef41Sopenharmony_ciconsole.log(`Oh, so your favorite food is ${answer}`); 5991cb0ef41Sopenharmony_ci``` 6001cb0ef41Sopenharmony_ci 6011cb0ef41Sopenharmony_ciUsing an `AbortSignal` to cancel a question. 6021cb0ef41Sopenharmony_ci 6031cb0ef41Sopenharmony_ci```mjs 6041cb0ef41Sopenharmony_ciconst signal = AbortSignal.timeout(10_000); 6051cb0ef41Sopenharmony_ci 6061cb0ef41Sopenharmony_cisignal.addEventListener('abort', () => { 6071cb0ef41Sopenharmony_ci console.log('The food question timed out'); 6081cb0ef41Sopenharmony_ci}, { once: true }); 6091cb0ef41Sopenharmony_ci 6101cb0ef41Sopenharmony_ciconst answer = await rl.question('What is your favorite food? ', { signal }); 6111cb0ef41Sopenharmony_ciconsole.log(`Oh, so your favorite food is ${answer}`); 6121cb0ef41Sopenharmony_ci``` 6131cb0ef41Sopenharmony_ci 6141cb0ef41Sopenharmony_ci### Class: `readlinePromises.Readline` 6151cb0ef41Sopenharmony_ci 6161cb0ef41Sopenharmony_ci<!-- YAML 6171cb0ef41Sopenharmony_ciadded: v17.0.0 6181cb0ef41Sopenharmony_ci--> 6191cb0ef41Sopenharmony_ci 6201cb0ef41Sopenharmony_ci#### `new readlinePromises.Readline(stream[, options])` 6211cb0ef41Sopenharmony_ci 6221cb0ef41Sopenharmony_ci<!-- YAML 6231cb0ef41Sopenharmony_ciadded: v17.0.0 6241cb0ef41Sopenharmony_ci--> 6251cb0ef41Sopenharmony_ci 6261cb0ef41Sopenharmony_ci* `stream` {stream.Writable} A [TTY][] stream. 6271cb0ef41Sopenharmony_ci* `options` {Object} 6281cb0ef41Sopenharmony_ci * `autoCommit` {boolean} If `true`, no need to call `rl.commit()`. 6291cb0ef41Sopenharmony_ci 6301cb0ef41Sopenharmony_ci#### `rl.clearLine(dir)` 6311cb0ef41Sopenharmony_ci 6321cb0ef41Sopenharmony_ci<!-- YAML 6331cb0ef41Sopenharmony_ciadded: v17.0.0 6341cb0ef41Sopenharmony_ci--> 6351cb0ef41Sopenharmony_ci 6361cb0ef41Sopenharmony_ci* `dir` {integer} 6371cb0ef41Sopenharmony_ci * `-1`: to the left from cursor 6381cb0ef41Sopenharmony_ci * `1`: to the right from cursor 6391cb0ef41Sopenharmony_ci * `0`: the entire line 6401cb0ef41Sopenharmony_ci* Returns: this 6411cb0ef41Sopenharmony_ci 6421cb0ef41Sopenharmony_ciThe `rl.clearLine()` method adds to the internal list of pending action an 6431cb0ef41Sopenharmony_ciaction that clears current line of the associated `stream` in a specified 6441cb0ef41Sopenharmony_cidirection identified by `dir`. 6451cb0ef41Sopenharmony_ciCall `rl.commit()` to see the effect of this method, unless `autoCommit: true` 6461cb0ef41Sopenharmony_ciwas passed to the constructor. 6471cb0ef41Sopenharmony_ci 6481cb0ef41Sopenharmony_ci#### `rl.clearScreenDown()` 6491cb0ef41Sopenharmony_ci 6501cb0ef41Sopenharmony_ci<!-- YAML 6511cb0ef41Sopenharmony_ciadded: v17.0.0 6521cb0ef41Sopenharmony_ci--> 6531cb0ef41Sopenharmony_ci 6541cb0ef41Sopenharmony_ci* Returns: this 6551cb0ef41Sopenharmony_ci 6561cb0ef41Sopenharmony_ciThe `rl.clearScreenDown()` method adds to the internal list of pending action an 6571cb0ef41Sopenharmony_ciaction that clears the associated stream from the current position of the 6581cb0ef41Sopenharmony_cicursor down. 6591cb0ef41Sopenharmony_ciCall `rl.commit()` to see the effect of this method, unless `autoCommit: true` 6601cb0ef41Sopenharmony_ciwas passed to the constructor. 6611cb0ef41Sopenharmony_ci 6621cb0ef41Sopenharmony_ci#### `rl.commit()` 6631cb0ef41Sopenharmony_ci 6641cb0ef41Sopenharmony_ci<!-- YAML 6651cb0ef41Sopenharmony_ciadded: v17.0.0 6661cb0ef41Sopenharmony_ci--> 6671cb0ef41Sopenharmony_ci 6681cb0ef41Sopenharmony_ci* Returns: {Promise} 6691cb0ef41Sopenharmony_ci 6701cb0ef41Sopenharmony_ciThe `rl.commit()` method sends all the pending actions to the associated 6711cb0ef41Sopenharmony_ci`stream` and clears the internal list of pending actions. 6721cb0ef41Sopenharmony_ci 6731cb0ef41Sopenharmony_ci#### `rl.cursorTo(x[, y])` 6741cb0ef41Sopenharmony_ci 6751cb0ef41Sopenharmony_ci<!-- YAML 6761cb0ef41Sopenharmony_ciadded: v17.0.0 6771cb0ef41Sopenharmony_ci--> 6781cb0ef41Sopenharmony_ci 6791cb0ef41Sopenharmony_ci* `x` {integer} 6801cb0ef41Sopenharmony_ci* `y` {integer} 6811cb0ef41Sopenharmony_ci* Returns: this 6821cb0ef41Sopenharmony_ci 6831cb0ef41Sopenharmony_ciThe `rl.cursorTo()` method adds to the internal list of pending action an action 6841cb0ef41Sopenharmony_cithat moves cursor to the specified position in the associated `stream`. 6851cb0ef41Sopenharmony_ciCall `rl.commit()` to see the effect of this method, unless `autoCommit: true` 6861cb0ef41Sopenharmony_ciwas passed to the constructor. 6871cb0ef41Sopenharmony_ci 6881cb0ef41Sopenharmony_ci#### `rl.moveCursor(dx, dy)` 6891cb0ef41Sopenharmony_ci 6901cb0ef41Sopenharmony_ci<!-- YAML 6911cb0ef41Sopenharmony_ciadded: v17.0.0 6921cb0ef41Sopenharmony_ci--> 6931cb0ef41Sopenharmony_ci 6941cb0ef41Sopenharmony_ci* `dx` {integer} 6951cb0ef41Sopenharmony_ci* `dy` {integer} 6961cb0ef41Sopenharmony_ci* Returns: this 6971cb0ef41Sopenharmony_ci 6981cb0ef41Sopenharmony_ciThe `rl.moveCursor()` method adds to the internal list of pending action an 6991cb0ef41Sopenharmony_ciaction that moves the cursor _relative_ to its current position in the 7001cb0ef41Sopenharmony_ciassociated `stream`. 7011cb0ef41Sopenharmony_ciCall `rl.commit()` to see the effect of this method, unless `autoCommit: true` 7021cb0ef41Sopenharmony_ciwas passed to the constructor. 7031cb0ef41Sopenharmony_ci 7041cb0ef41Sopenharmony_ci#### `rl.rollback()` 7051cb0ef41Sopenharmony_ci 7061cb0ef41Sopenharmony_ci<!-- YAML 7071cb0ef41Sopenharmony_ciadded: v17.0.0 7081cb0ef41Sopenharmony_ci--> 7091cb0ef41Sopenharmony_ci 7101cb0ef41Sopenharmony_ci* Returns: this 7111cb0ef41Sopenharmony_ci 7121cb0ef41Sopenharmony_ciThe `rl.rollback` methods clears the internal list of pending actions without 7131cb0ef41Sopenharmony_cisending it to the associated `stream`. 7141cb0ef41Sopenharmony_ci 7151cb0ef41Sopenharmony_ci### `readlinePromises.createInterface(options)` 7161cb0ef41Sopenharmony_ci 7171cb0ef41Sopenharmony_ci<!-- YAML 7181cb0ef41Sopenharmony_ciadded: v17.0.0 7191cb0ef41Sopenharmony_ci--> 7201cb0ef41Sopenharmony_ci 7211cb0ef41Sopenharmony_ci* `options` {Object} 7221cb0ef41Sopenharmony_ci * `input` {stream.Readable} The [Readable][] stream to listen to. This option 7231cb0ef41Sopenharmony_ci is _required_. 7241cb0ef41Sopenharmony_ci * `output` {stream.Writable} The [Writable][] stream to write readline data 7251cb0ef41Sopenharmony_ci to. 7261cb0ef41Sopenharmony_ci * `completer` {Function} An optional function used for Tab autocompletion. 7271cb0ef41Sopenharmony_ci * `terminal` {boolean} `true` if the `input` and `output` streams should be 7281cb0ef41Sopenharmony_ci treated like a TTY, and have ANSI/VT100 escape codes written to it. 7291cb0ef41Sopenharmony_ci **Default:** checking `isTTY` on the `output` stream upon instantiation. 7301cb0ef41Sopenharmony_ci * `history` {string\[]} Initial list of history lines. This option makes sense 7311cb0ef41Sopenharmony_ci only if `terminal` is set to `true` by the user or by an internal `output` 7321cb0ef41Sopenharmony_ci check, otherwise the history caching mechanism is not initialized at all. 7331cb0ef41Sopenharmony_ci **Default:** `[]`. 7341cb0ef41Sopenharmony_ci * `historySize` {number} Maximum number of history lines retained. To disable 7351cb0ef41Sopenharmony_ci the history set this value to `0`. This option makes sense only if 7361cb0ef41Sopenharmony_ci `terminal` is set to `true` by the user or by an internal `output` check, 7371cb0ef41Sopenharmony_ci otherwise the history caching mechanism is not initialized at all. 7381cb0ef41Sopenharmony_ci **Default:** `30`. 7391cb0ef41Sopenharmony_ci * `removeHistoryDuplicates` {boolean} If `true`, when a new input line added 7401cb0ef41Sopenharmony_ci to the history list duplicates an older one, this removes the older line 7411cb0ef41Sopenharmony_ci from the list. **Default:** `false`. 7421cb0ef41Sopenharmony_ci * `prompt` {string} The prompt string to use. **Default:** `'> '`. 7431cb0ef41Sopenharmony_ci * `crlfDelay` {number} If the delay between `\r` and `\n` exceeds 7441cb0ef41Sopenharmony_ci `crlfDelay` milliseconds, both `\r` and `\n` will be treated as separate 7451cb0ef41Sopenharmony_ci end-of-line input. `crlfDelay` will be coerced to a number no less than 7461cb0ef41Sopenharmony_ci `100`. It can be set to `Infinity`, in which case `\r` followed by `\n` 7471cb0ef41Sopenharmony_ci will always be considered a single newline (which may be reasonable for 7481cb0ef41Sopenharmony_ci [reading files][] with `\r\n` line delimiter). **Default:** `100`. 7491cb0ef41Sopenharmony_ci * `escapeCodeTimeout` {number} The duration `readlinePromises` will wait for a 7501cb0ef41Sopenharmony_ci character (when reading an ambiguous key sequence in milliseconds one that 7511cb0ef41Sopenharmony_ci can both form a complete key sequence using the input read so far and can 7521cb0ef41Sopenharmony_ci take additional input to complete a longer key sequence). 7531cb0ef41Sopenharmony_ci **Default:** `500`. 7541cb0ef41Sopenharmony_ci * `tabSize` {integer} The number of spaces a tab is equal to (minimum 1). 7551cb0ef41Sopenharmony_ci **Default:** `8`. 7561cb0ef41Sopenharmony_ci* Returns: {readlinePromises.Interface} 7571cb0ef41Sopenharmony_ci 7581cb0ef41Sopenharmony_ciThe `readlinePromises.createInterface()` method creates a new `readlinePromises.Interface` 7591cb0ef41Sopenharmony_ciinstance. 7601cb0ef41Sopenharmony_ci 7611cb0ef41Sopenharmony_ci```js 7621cb0ef41Sopenharmony_ciconst readlinePromises = require('node:readline/promises'); 7631cb0ef41Sopenharmony_ciconst rl = readlinePromises.createInterface({ 7641cb0ef41Sopenharmony_ci input: process.stdin, 7651cb0ef41Sopenharmony_ci output: process.stdout, 7661cb0ef41Sopenharmony_ci}); 7671cb0ef41Sopenharmony_ci``` 7681cb0ef41Sopenharmony_ci 7691cb0ef41Sopenharmony_ciOnce the `readlinePromises.Interface` instance is created, the most common case 7701cb0ef41Sopenharmony_ciis to listen for the `'line'` event: 7711cb0ef41Sopenharmony_ci 7721cb0ef41Sopenharmony_ci```js 7731cb0ef41Sopenharmony_cirl.on('line', (line) => { 7741cb0ef41Sopenharmony_ci console.log(`Received: ${line}`); 7751cb0ef41Sopenharmony_ci}); 7761cb0ef41Sopenharmony_ci``` 7771cb0ef41Sopenharmony_ci 7781cb0ef41Sopenharmony_ciIf `terminal` is `true` for this instance then the `output` stream will get 7791cb0ef41Sopenharmony_cithe best compatibility if it defines an `output.columns` property and emits 7801cb0ef41Sopenharmony_cia `'resize'` event on the `output` if or when the columns ever change 7811cb0ef41Sopenharmony_ci([`process.stdout`][] does this automatically when it is a TTY). 7821cb0ef41Sopenharmony_ci 7831cb0ef41Sopenharmony_ci#### Use of the `completer` function 7841cb0ef41Sopenharmony_ci 7851cb0ef41Sopenharmony_ciThe `completer` function takes the current line entered by the user 7861cb0ef41Sopenharmony_cias an argument, and returns an `Array` with 2 entries: 7871cb0ef41Sopenharmony_ci 7881cb0ef41Sopenharmony_ci* An `Array` with matching entries for the completion. 7891cb0ef41Sopenharmony_ci* The substring that was used for the matching. 7901cb0ef41Sopenharmony_ci 7911cb0ef41Sopenharmony_ciFor instance: `[[substr1, substr2, ...], originalsubstring]`. 7921cb0ef41Sopenharmony_ci 7931cb0ef41Sopenharmony_ci```js 7941cb0ef41Sopenharmony_cifunction completer(line) { 7951cb0ef41Sopenharmony_ci const completions = '.help .error .exit .quit .q'.split(' '); 7961cb0ef41Sopenharmony_ci const hits = completions.filter((c) => c.startsWith(line)); 7971cb0ef41Sopenharmony_ci // Show all completions if none found 7981cb0ef41Sopenharmony_ci return [hits.length ? hits : completions, line]; 7991cb0ef41Sopenharmony_ci} 8001cb0ef41Sopenharmony_ci``` 8011cb0ef41Sopenharmony_ci 8021cb0ef41Sopenharmony_ciThe `completer` function can also return a {Promise}, or be asynchronous: 8031cb0ef41Sopenharmony_ci 8041cb0ef41Sopenharmony_ci```js 8051cb0ef41Sopenharmony_ciasync function completer(linePartial) { 8061cb0ef41Sopenharmony_ci await someAsyncWork(); 8071cb0ef41Sopenharmony_ci return [['123'], linePartial]; 8081cb0ef41Sopenharmony_ci} 8091cb0ef41Sopenharmony_ci``` 8101cb0ef41Sopenharmony_ci 8111cb0ef41Sopenharmony_ci## Callback API 8121cb0ef41Sopenharmony_ci 8131cb0ef41Sopenharmony_ci<!-- YAML 8141cb0ef41Sopenharmony_ciadded: v0.1.104 8151cb0ef41Sopenharmony_ci--> 8161cb0ef41Sopenharmony_ci 8171cb0ef41Sopenharmony_ci### Class: `readline.Interface` 8181cb0ef41Sopenharmony_ci 8191cb0ef41Sopenharmony_ci<!-- YAML 8201cb0ef41Sopenharmony_ciadded: v0.1.104 8211cb0ef41Sopenharmony_cichanges: 8221cb0ef41Sopenharmony_ci - version: v17.0.0 8231cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/37947 8241cb0ef41Sopenharmony_ci description: The class `readline.Interface` now inherits from `Interface`. 8251cb0ef41Sopenharmony_ci--> 8261cb0ef41Sopenharmony_ci 8271cb0ef41Sopenharmony_ci* Extends: {readline.InterfaceConstructor} 8281cb0ef41Sopenharmony_ci 8291cb0ef41Sopenharmony_ciInstances of the `readline.Interface` class are constructed using the 8301cb0ef41Sopenharmony_ci`readline.createInterface()` method. Every instance is associated with a 8311cb0ef41Sopenharmony_cisingle `input` [Readable][] stream and a single `output` [Writable][] stream. 8321cb0ef41Sopenharmony_ciThe `output` stream is used to print prompts for user input that arrives on, 8331cb0ef41Sopenharmony_ciand is read from, the `input` stream. 8341cb0ef41Sopenharmony_ci 8351cb0ef41Sopenharmony_ci#### `rl.question(query[, options], callback)` 8361cb0ef41Sopenharmony_ci 8371cb0ef41Sopenharmony_ci<!-- YAML 8381cb0ef41Sopenharmony_ciadded: v0.3.3 8391cb0ef41Sopenharmony_ci--> 8401cb0ef41Sopenharmony_ci 8411cb0ef41Sopenharmony_ci* `query` {string} A statement or query to write to `output`, prepended to the 8421cb0ef41Sopenharmony_ci prompt. 8431cb0ef41Sopenharmony_ci* `options` {Object} 8441cb0ef41Sopenharmony_ci * `signal` {AbortSignal} Optionally allows the `question()` to be canceled 8451cb0ef41Sopenharmony_ci using an `AbortController`. 8461cb0ef41Sopenharmony_ci* `callback` {Function} A callback function that is invoked with the user's 8471cb0ef41Sopenharmony_ci input in response to the `query`. 8481cb0ef41Sopenharmony_ci 8491cb0ef41Sopenharmony_ciThe `rl.question()` method displays the `query` by writing it to the `output`, 8501cb0ef41Sopenharmony_ciwaits for user input to be provided on `input`, then invokes the `callback` 8511cb0ef41Sopenharmony_cifunction passing the provided input as the first argument. 8521cb0ef41Sopenharmony_ci 8531cb0ef41Sopenharmony_ciWhen called, `rl.question()` will resume the `input` stream if it has been 8541cb0ef41Sopenharmony_cipaused. 8551cb0ef41Sopenharmony_ci 8561cb0ef41Sopenharmony_ciIf the `readline.Interface` was created with `output` set to `null` or 8571cb0ef41Sopenharmony_ci`undefined` the `query` is not written. 8581cb0ef41Sopenharmony_ci 8591cb0ef41Sopenharmony_ciThe `callback` function passed to `rl.question()` does not follow the typical 8601cb0ef41Sopenharmony_cipattern of accepting an `Error` object or `null` as the first argument. 8611cb0ef41Sopenharmony_ciThe `callback` is called with the provided answer as the only argument. 8621cb0ef41Sopenharmony_ci 8631cb0ef41Sopenharmony_ciAn error will be thrown if calling `rl.question()` after `rl.close()`. 8641cb0ef41Sopenharmony_ci 8651cb0ef41Sopenharmony_ciExample usage: 8661cb0ef41Sopenharmony_ci 8671cb0ef41Sopenharmony_ci```js 8681cb0ef41Sopenharmony_cirl.question('What is your favorite food? ', (answer) => { 8691cb0ef41Sopenharmony_ci console.log(`Oh, so your favorite food is ${answer}`); 8701cb0ef41Sopenharmony_ci}); 8711cb0ef41Sopenharmony_ci``` 8721cb0ef41Sopenharmony_ci 8731cb0ef41Sopenharmony_ciUsing an `AbortController` to cancel a question. 8741cb0ef41Sopenharmony_ci 8751cb0ef41Sopenharmony_ci```js 8761cb0ef41Sopenharmony_ciconst ac = new AbortController(); 8771cb0ef41Sopenharmony_ciconst signal = ac.signal; 8781cb0ef41Sopenharmony_ci 8791cb0ef41Sopenharmony_cirl.question('What is your favorite food? ', { signal }, (answer) => { 8801cb0ef41Sopenharmony_ci console.log(`Oh, so your favorite food is ${answer}`); 8811cb0ef41Sopenharmony_ci}); 8821cb0ef41Sopenharmony_ci 8831cb0ef41Sopenharmony_cisignal.addEventListener('abort', () => { 8841cb0ef41Sopenharmony_ci console.log('The food question timed out'); 8851cb0ef41Sopenharmony_ci}, { once: true }); 8861cb0ef41Sopenharmony_ci 8871cb0ef41Sopenharmony_cisetTimeout(() => ac.abort(), 10000); 8881cb0ef41Sopenharmony_ci``` 8891cb0ef41Sopenharmony_ci 8901cb0ef41Sopenharmony_ci### `readline.clearLine(stream, dir[, callback])` 8911cb0ef41Sopenharmony_ci 8921cb0ef41Sopenharmony_ci<!-- YAML 8931cb0ef41Sopenharmony_ciadded: v0.7.7 8941cb0ef41Sopenharmony_cichanges: 8951cb0ef41Sopenharmony_ci - version: v18.0.0 8961cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/41678 8971cb0ef41Sopenharmony_ci description: Passing an invalid callback to the `callback` argument 8981cb0ef41Sopenharmony_ci now throws `ERR_INVALID_ARG_TYPE` instead of 8991cb0ef41Sopenharmony_ci `ERR_INVALID_CALLBACK`. 9001cb0ef41Sopenharmony_ci - version: v12.7.0 9011cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/28674 9021cb0ef41Sopenharmony_ci description: The stream's write() callback and return value are exposed. 9031cb0ef41Sopenharmony_ci--> 9041cb0ef41Sopenharmony_ci 9051cb0ef41Sopenharmony_ci* `stream` {stream.Writable} 9061cb0ef41Sopenharmony_ci* `dir` {number} 9071cb0ef41Sopenharmony_ci * `-1`: to the left from cursor 9081cb0ef41Sopenharmony_ci * `1`: to the right from cursor 9091cb0ef41Sopenharmony_ci * `0`: the entire line 9101cb0ef41Sopenharmony_ci* `callback` {Function} Invoked once the operation completes. 9111cb0ef41Sopenharmony_ci* Returns: {boolean} `false` if `stream` wishes for the calling code to wait for 9121cb0ef41Sopenharmony_ci the `'drain'` event to be emitted before continuing to write additional data; 9131cb0ef41Sopenharmony_ci otherwise `true`. 9141cb0ef41Sopenharmony_ci 9151cb0ef41Sopenharmony_ciThe `readline.clearLine()` method clears current line of given [TTY][] stream 9161cb0ef41Sopenharmony_ciin a specified direction identified by `dir`. 9171cb0ef41Sopenharmony_ci 9181cb0ef41Sopenharmony_ci### `readline.clearScreenDown(stream[, callback])` 9191cb0ef41Sopenharmony_ci 9201cb0ef41Sopenharmony_ci<!-- YAML 9211cb0ef41Sopenharmony_ciadded: v0.7.7 9221cb0ef41Sopenharmony_cichanges: 9231cb0ef41Sopenharmony_ci - version: v18.0.0 9241cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/41678 9251cb0ef41Sopenharmony_ci description: Passing an invalid callback to the `callback` argument 9261cb0ef41Sopenharmony_ci now throws `ERR_INVALID_ARG_TYPE` instead of 9271cb0ef41Sopenharmony_ci `ERR_INVALID_CALLBACK`. 9281cb0ef41Sopenharmony_ci - version: v12.7.0 9291cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/28641 9301cb0ef41Sopenharmony_ci description: The stream's write() callback and return value are exposed. 9311cb0ef41Sopenharmony_ci--> 9321cb0ef41Sopenharmony_ci 9331cb0ef41Sopenharmony_ci* `stream` {stream.Writable} 9341cb0ef41Sopenharmony_ci* `callback` {Function} Invoked once the operation completes. 9351cb0ef41Sopenharmony_ci* Returns: {boolean} `false` if `stream` wishes for the calling code to wait for 9361cb0ef41Sopenharmony_ci the `'drain'` event to be emitted before continuing to write additional data; 9371cb0ef41Sopenharmony_ci otherwise `true`. 9381cb0ef41Sopenharmony_ci 9391cb0ef41Sopenharmony_ciThe `readline.clearScreenDown()` method clears the given [TTY][] stream from 9401cb0ef41Sopenharmony_cithe current position of the cursor down. 9411cb0ef41Sopenharmony_ci 9421cb0ef41Sopenharmony_ci### `readline.createInterface(options)` 9431cb0ef41Sopenharmony_ci 9441cb0ef41Sopenharmony_ci<!-- YAML 9451cb0ef41Sopenharmony_ciadded: v0.1.98 9461cb0ef41Sopenharmony_cichanges: 9471cb0ef41Sopenharmony_ci - version: 9481cb0ef41Sopenharmony_ci - v15.14.0 9491cb0ef41Sopenharmony_ci - v14.18.0 9501cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/37932 9511cb0ef41Sopenharmony_ci description: The `signal` option is supported now. 9521cb0ef41Sopenharmony_ci - version: 9531cb0ef41Sopenharmony_ci - v15.8.0 9541cb0ef41Sopenharmony_ci - v14.18.0 9551cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/33662 9561cb0ef41Sopenharmony_ci description: The `history` option is supported now. 9571cb0ef41Sopenharmony_ci - version: v13.9.0 9581cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/31318 9591cb0ef41Sopenharmony_ci description: The `tabSize` option is supported now. 9601cb0ef41Sopenharmony_ci - version: 9611cb0ef41Sopenharmony_ci - v8.3.0 9621cb0ef41Sopenharmony_ci - v6.11.4 9631cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/13497 9641cb0ef41Sopenharmony_ci description: Remove max limit of `crlfDelay` option. 9651cb0ef41Sopenharmony_ci - version: v6.6.0 9661cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/8109 9671cb0ef41Sopenharmony_ci description: The `crlfDelay` option is supported now. 9681cb0ef41Sopenharmony_ci - version: v6.3.0 9691cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/7125 9701cb0ef41Sopenharmony_ci description: The `prompt` option is supported now. 9711cb0ef41Sopenharmony_ci - version: v6.0.0 9721cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/6352 9731cb0ef41Sopenharmony_ci description: The `historySize` option can be `0` now. 9741cb0ef41Sopenharmony_ci--> 9751cb0ef41Sopenharmony_ci 9761cb0ef41Sopenharmony_ci* `options` {Object} 9771cb0ef41Sopenharmony_ci * `input` {stream.Readable} The [Readable][] stream to listen to. This option 9781cb0ef41Sopenharmony_ci is _required_. 9791cb0ef41Sopenharmony_ci * `output` {stream.Writable} The [Writable][] stream to write readline data 9801cb0ef41Sopenharmony_ci to. 9811cb0ef41Sopenharmony_ci * `completer` {Function} An optional function used for Tab autocompletion. 9821cb0ef41Sopenharmony_ci * `terminal` {boolean} `true` if the `input` and `output` streams should be 9831cb0ef41Sopenharmony_ci treated like a TTY, and have ANSI/VT100 escape codes written to it. 9841cb0ef41Sopenharmony_ci **Default:** checking `isTTY` on the `output` stream upon instantiation. 9851cb0ef41Sopenharmony_ci * `history` {string\[]} Initial list of history lines. This option makes sense 9861cb0ef41Sopenharmony_ci only if `terminal` is set to `true` by the user or by an internal `output` 9871cb0ef41Sopenharmony_ci check, otherwise the history caching mechanism is not initialized at all. 9881cb0ef41Sopenharmony_ci **Default:** `[]`. 9891cb0ef41Sopenharmony_ci * `historySize` {number} Maximum number of history lines retained. To disable 9901cb0ef41Sopenharmony_ci the history set this value to `0`. This option makes sense only if 9911cb0ef41Sopenharmony_ci `terminal` is set to `true` by the user or by an internal `output` check, 9921cb0ef41Sopenharmony_ci otherwise the history caching mechanism is not initialized at all. 9931cb0ef41Sopenharmony_ci **Default:** `30`. 9941cb0ef41Sopenharmony_ci * `removeHistoryDuplicates` {boolean} If `true`, when a new input line added 9951cb0ef41Sopenharmony_ci to the history list duplicates an older one, this removes the older line 9961cb0ef41Sopenharmony_ci from the list. **Default:** `false`. 9971cb0ef41Sopenharmony_ci * `prompt` {string} The prompt string to use. **Default:** `'> '`. 9981cb0ef41Sopenharmony_ci * `crlfDelay` {number} If the delay between `\r` and `\n` exceeds 9991cb0ef41Sopenharmony_ci `crlfDelay` milliseconds, both `\r` and `\n` will be treated as separate 10001cb0ef41Sopenharmony_ci end-of-line input. `crlfDelay` will be coerced to a number no less than 10011cb0ef41Sopenharmony_ci `100`. It can be set to `Infinity`, in which case `\r` followed by `\n` 10021cb0ef41Sopenharmony_ci will always be considered a single newline (which may be reasonable for 10031cb0ef41Sopenharmony_ci [reading files][] with `\r\n` line delimiter). **Default:** `100`. 10041cb0ef41Sopenharmony_ci * `escapeCodeTimeout` {number} The duration `readline` will wait for a 10051cb0ef41Sopenharmony_ci character (when reading an ambiguous key sequence in milliseconds one that 10061cb0ef41Sopenharmony_ci can both form a complete key sequence using the input read so far and can 10071cb0ef41Sopenharmony_ci take additional input to complete a longer key sequence). 10081cb0ef41Sopenharmony_ci **Default:** `500`. 10091cb0ef41Sopenharmony_ci * `tabSize` {integer} The number of spaces a tab is equal to (minimum 1). 10101cb0ef41Sopenharmony_ci **Default:** `8`. 10111cb0ef41Sopenharmony_ci * `signal` {AbortSignal} Allows closing the interface using an AbortSignal. 10121cb0ef41Sopenharmony_ci Aborting the signal will internally call `close` on the interface. 10131cb0ef41Sopenharmony_ci* Returns: {readline.Interface} 10141cb0ef41Sopenharmony_ci 10151cb0ef41Sopenharmony_ciThe `readline.createInterface()` method creates a new `readline.Interface` 10161cb0ef41Sopenharmony_ciinstance. 10171cb0ef41Sopenharmony_ci 10181cb0ef41Sopenharmony_ci```js 10191cb0ef41Sopenharmony_ciconst readline = require('node:readline'); 10201cb0ef41Sopenharmony_ciconst rl = readline.createInterface({ 10211cb0ef41Sopenharmony_ci input: process.stdin, 10221cb0ef41Sopenharmony_ci output: process.stdout, 10231cb0ef41Sopenharmony_ci}); 10241cb0ef41Sopenharmony_ci``` 10251cb0ef41Sopenharmony_ci 10261cb0ef41Sopenharmony_ciOnce the `readline.Interface` instance is created, the most common case is to 10271cb0ef41Sopenharmony_cilisten for the `'line'` event: 10281cb0ef41Sopenharmony_ci 10291cb0ef41Sopenharmony_ci```js 10301cb0ef41Sopenharmony_cirl.on('line', (line) => { 10311cb0ef41Sopenharmony_ci console.log(`Received: ${line}`); 10321cb0ef41Sopenharmony_ci}); 10331cb0ef41Sopenharmony_ci``` 10341cb0ef41Sopenharmony_ci 10351cb0ef41Sopenharmony_ciIf `terminal` is `true` for this instance then the `output` stream will get 10361cb0ef41Sopenharmony_cithe best compatibility if it defines an `output.columns` property and emits 10371cb0ef41Sopenharmony_cia `'resize'` event on the `output` if or when the columns ever change 10381cb0ef41Sopenharmony_ci([`process.stdout`][] does this automatically when it is a TTY). 10391cb0ef41Sopenharmony_ci 10401cb0ef41Sopenharmony_ciWhen creating a `readline.Interface` using `stdin` as input, the program 10411cb0ef41Sopenharmony_ciwill not terminate until it receives an [EOF character][]. To exit without 10421cb0ef41Sopenharmony_ciwaiting for user input, call `process.stdin.unref()`. 10431cb0ef41Sopenharmony_ci 10441cb0ef41Sopenharmony_ci#### Use of the `completer` function 10451cb0ef41Sopenharmony_ci 10461cb0ef41Sopenharmony_ciThe `completer` function takes the current line entered by the user 10471cb0ef41Sopenharmony_cias an argument, and returns an `Array` with 2 entries: 10481cb0ef41Sopenharmony_ci 10491cb0ef41Sopenharmony_ci* An `Array` with matching entries for the completion. 10501cb0ef41Sopenharmony_ci* The substring that was used for the matching. 10511cb0ef41Sopenharmony_ci 10521cb0ef41Sopenharmony_ciFor instance: `[[substr1, substr2, ...], originalsubstring]`. 10531cb0ef41Sopenharmony_ci 10541cb0ef41Sopenharmony_ci```js 10551cb0ef41Sopenharmony_cifunction completer(line) { 10561cb0ef41Sopenharmony_ci const completions = '.help .error .exit .quit .q'.split(' '); 10571cb0ef41Sopenharmony_ci const hits = completions.filter((c) => c.startsWith(line)); 10581cb0ef41Sopenharmony_ci // Show all completions if none found 10591cb0ef41Sopenharmony_ci return [hits.length ? hits : completions, line]; 10601cb0ef41Sopenharmony_ci} 10611cb0ef41Sopenharmony_ci``` 10621cb0ef41Sopenharmony_ci 10631cb0ef41Sopenharmony_ciThe `completer` function can be called asynchronously if it accepts two 10641cb0ef41Sopenharmony_ciarguments: 10651cb0ef41Sopenharmony_ci 10661cb0ef41Sopenharmony_ci```js 10671cb0ef41Sopenharmony_cifunction completer(linePartial, callback) { 10681cb0ef41Sopenharmony_ci callback(null, [['123'], linePartial]); 10691cb0ef41Sopenharmony_ci} 10701cb0ef41Sopenharmony_ci``` 10711cb0ef41Sopenharmony_ci 10721cb0ef41Sopenharmony_ci### `readline.cursorTo(stream, x[, y][, callback])` 10731cb0ef41Sopenharmony_ci 10741cb0ef41Sopenharmony_ci<!-- YAML 10751cb0ef41Sopenharmony_ciadded: v0.7.7 10761cb0ef41Sopenharmony_cichanges: 10771cb0ef41Sopenharmony_ci - version: v18.0.0 10781cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/41678 10791cb0ef41Sopenharmony_ci description: Passing an invalid callback to the `callback` argument 10801cb0ef41Sopenharmony_ci now throws `ERR_INVALID_ARG_TYPE` instead of 10811cb0ef41Sopenharmony_ci `ERR_INVALID_CALLBACK`. 10821cb0ef41Sopenharmony_ci - version: v12.7.0 10831cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/28674 10841cb0ef41Sopenharmony_ci description: The stream's write() callback and return value are exposed. 10851cb0ef41Sopenharmony_ci--> 10861cb0ef41Sopenharmony_ci 10871cb0ef41Sopenharmony_ci* `stream` {stream.Writable} 10881cb0ef41Sopenharmony_ci* `x` {number} 10891cb0ef41Sopenharmony_ci* `y` {number} 10901cb0ef41Sopenharmony_ci* `callback` {Function} Invoked once the operation completes. 10911cb0ef41Sopenharmony_ci* Returns: {boolean} `false` if `stream` wishes for the calling code to wait for 10921cb0ef41Sopenharmony_ci the `'drain'` event to be emitted before continuing to write additional data; 10931cb0ef41Sopenharmony_ci otherwise `true`. 10941cb0ef41Sopenharmony_ci 10951cb0ef41Sopenharmony_ciThe `readline.cursorTo()` method moves cursor to the specified position in a 10961cb0ef41Sopenharmony_cigiven [TTY][] `stream`. 10971cb0ef41Sopenharmony_ci 10981cb0ef41Sopenharmony_ci### `readline.moveCursor(stream, dx, dy[, callback])` 10991cb0ef41Sopenharmony_ci 11001cb0ef41Sopenharmony_ci<!-- YAML 11011cb0ef41Sopenharmony_ciadded: v0.7.7 11021cb0ef41Sopenharmony_cichanges: 11031cb0ef41Sopenharmony_ci - version: v18.0.0 11041cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/41678 11051cb0ef41Sopenharmony_ci description: Passing an invalid callback to the `callback` argument 11061cb0ef41Sopenharmony_ci now throws `ERR_INVALID_ARG_TYPE` instead of 11071cb0ef41Sopenharmony_ci `ERR_INVALID_CALLBACK`. 11081cb0ef41Sopenharmony_ci - version: v12.7.0 11091cb0ef41Sopenharmony_ci pr-url: https://github.com/nodejs/node/pull/28674 11101cb0ef41Sopenharmony_ci description: The stream's write() callback and return value are exposed. 11111cb0ef41Sopenharmony_ci--> 11121cb0ef41Sopenharmony_ci 11131cb0ef41Sopenharmony_ci* `stream` {stream.Writable} 11141cb0ef41Sopenharmony_ci* `dx` {number} 11151cb0ef41Sopenharmony_ci* `dy` {number} 11161cb0ef41Sopenharmony_ci* `callback` {Function} Invoked once the operation completes. 11171cb0ef41Sopenharmony_ci* Returns: {boolean} `false` if `stream` wishes for the calling code to wait for 11181cb0ef41Sopenharmony_ci the `'drain'` event to be emitted before continuing to write additional data; 11191cb0ef41Sopenharmony_ci otherwise `true`. 11201cb0ef41Sopenharmony_ci 11211cb0ef41Sopenharmony_ciThe `readline.moveCursor()` method moves the cursor _relative_ to its current 11221cb0ef41Sopenharmony_ciposition in a given [TTY][] `stream`. 11231cb0ef41Sopenharmony_ci 11241cb0ef41Sopenharmony_ci## `readline.emitKeypressEvents(stream[, interface])` 11251cb0ef41Sopenharmony_ci 11261cb0ef41Sopenharmony_ci<!-- YAML 11271cb0ef41Sopenharmony_ciadded: v0.7.7 11281cb0ef41Sopenharmony_ci--> 11291cb0ef41Sopenharmony_ci 11301cb0ef41Sopenharmony_ci* `stream` {stream.Readable} 11311cb0ef41Sopenharmony_ci* `interface` {readline.InterfaceConstructor} 11321cb0ef41Sopenharmony_ci 11331cb0ef41Sopenharmony_ciThe `readline.emitKeypressEvents()` method causes the given [Readable][] 11341cb0ef41Sopenharmony_cistream to begin emitting `'keypress'` events corresponding to received input. 11351cb0ef41Sopenharmony_ci 11361cb0ef41Sopenharmony_ciOptionally, `interface` specifies a `readline.Interface` instance for which 11371cb0ef41Sopenharmony_ciautocompletion is disabled when copy-pasted input is detected. 11381cb0ef41Sopenharmony_ci 11391cb0ef41Sopenharmony_ciIf the `stream` is a [TTY][], then it must be in raw mode. 11401cb0ef41Sopenharmony_ci 11411cb0ef41Sopenharmony_ciThis is automatically called by any readline instance on its `input` if the 11421cb0ef41Sopenharmony_ci`input` is a terminal. Closing the `readline` instance does not stop 11431cb0ef41Sopenharmony_cithe `input` from emitting `'keypress'` events. 11441cb0ef41Sopenharmony_ci 11451cb0ef41Sopenharmony_ci```js 11461cb0ef41Sopenharmony_cireadline.emitKeypressEvents(process.stdin); 11471cb0ef41Sopenharmony_ciif (process.stdin.isTTY) 11481cb0ef41Sopenharmony_ci process.stdin.setRawMode(true); 11491cb0ef41Sopenharmony_ci``` 11501cb0ef41Sopenharmony_ci 11511cb0ef41Sopenharmony_ci## Example: Tiny CLI 11521cb0ef41Sopenharmony_ci 11531cb0ef41Sopenharmony_ciThe following example illustrates the use of `readline.Interface` class to 11541cb0ef41Sopenharmony_ciimplement a small command-line interface: 11551cb0ef41Sopenharmony_ci 11561cb0ef41Sopenharmony_ci```js 11571cb0ef41Sopenharmony_ciconst readline = require('node:readline'); 11581cb0ef41Sopenharmony_ciconst rl = readline.createInterface({ 11591cb0ef41Sopenharmony_ci input: process.stdin, 11601cb0ef41Sopenharmony_ci output: process.stdout, 11611cb0ef41Sopenharmony_ci prompt: 'OHAI> ', 11621cb0ef41Sopenharmony_ci}); 11631cb0ef41Sopenharmony_ci 11641cb0ef41Sopenharmony_cirl.prompt(); 11651cb0ef41Sopenharmony_ci 11661cb0ef41Sopenharmony_cirl.on('line', (line) => { 11671cb0ef41Sopenharmony_ci switch (line.trim()) { 11681cb0ef41Sopenharmony_ci case 'hello': 11691cb0ef41Sopenharmony_ci console.log('world!'); 11701cb0ef41Sopenharmony_ci break; 11711cb0ef41Sopenharmony_ci default: 11721cb0ef41Sopenharmony_ci console.log(`Say what? I might have heard '${line.trim()}'`); 11731cb0ef41Sopenharmony_ci break; 11741cb0ef41Sopenharmony_ci } 11751cb0ef41Sopenharmony_ci rl.prompt(); 11761cb0ef41Sopenharmony_ci}).on('close', () => { 11771cb0ef41Sopenharmony_ci console.log('Have a great day!'); 11781cb0ef41Sopenharmony_ci process.exit(0); 11791cb0ef41Sopenharmony_ci}); 11801cb0ef41Sopenharmony_ci``` 11811cb0ef41Sopenharmony_ci 11821cb0ef41Sopenharmony_ci## Example: Read file stream line-by-Line 11831cb0ef41Sopenharmony_ci 11841cb0ef41Sopenharmony_ciA common use case for `readline` is to consume an input file one line at a 11851cb0ef41Sopenharmony_citime. The easiest way to do so is leveraging the [`fs.ReadStream`][] API as 11861cb0ef41Sopenharmony_ciwell as a `for await...of` loop: 11871cb0ef41Sopenharmony_ci 11881cb0ef41Sopenharmony_ci```js 11891cb0ef41Sopenharmony_ciconst fs = require('node:fs'); 11901cb0ef41Sopenharmony_ciconst readline = require('node:readline'); 11911cb0ef41Sopenharmony_ci 11921cb0ef41Sopenharmony_ciasync function processLineByLine() { 11931cb0ef41Sopenharmony_ci const fileStream = fs.createReadStream('input.txt'); 11941cb0ef41Sopenharmony_ci 11951cb0ef41Sopenharmony_ci const rl = readline.createInterface({ 11961cb0ef41Sopenharmony_ci input: fileStream, 11971cb0ef41Sopenharmony_ci crlfDelay: Infinity, 11981cb0ef41Sopenharmony_ci }); 11991cb0ef41Sopenharmony_ci // Note: we use the crlfDelay option to recognize all instances of CR LF 12001cb0ef41Sopenharmony_ci // ('\r\n') in input.txt as a single line break. 12011cb0ef41Sopenharmony_ci 12021cb0ef41Sopenharmony_ci for await (const line of rl) { 12031cb0ef41Sopenharmony_ci // Each line in input.txt will be successively available here as `line`. 12041cb0ef41Sopenharmony_ci console.log(`Line from file: ${line}`); 12051cb0ef41Sopenharmony_ci } 12061cb0ef41Sopenharmony_ci} 12071cb0ef41Sopenharmony_ci 12081cb0ef41Sopenharmony_ciprocessLineByLine(); 12091cb0ef41Sopenharmony_ci``` 12101cb0ef41Sopenharmony_ci 12111cb0ef41Sopenharmony_ciAlternatively, one could use the [`'line'`][] event: 12121cb0ef41Sopenharmony_ci 12131cb0ef41Sopenharmony_ci```js 12141cb0ef41Sopenharmony_ciconst fs = require('node:fs'); 12151cb0ef41Sopenharmony_ciconst readline = require('node:readline'); 12161cb0ef41Sopenharmony_ci 12171cb0ef41Sopenharmony_ciconst rl = readline.createInterface({ 12181cb0ef41Sopenharmony_ci input: fs.createReadStream('sample.txt'), 12191cb0ef41Sopenharmony_ci crlfDelay: Infinity, 12201cb0ef41Sopenharmony_ci}); 12211cb0ef41Sopenharmony_ci 12221cb0ef41Sopenharmony_cirl.on('line', (line) => { 12231cb0ef41Sopenharmony_ci console.log(`Line from file: ${line}`); 12241cb0ef41Sopenharmony_ci}); 12251cb0ef41Sopenharmony_ci``` 12261cb0ef41Sopenharmony_ci 12271cb0ef41Sopenharmony_ciCurrently, `for await...of` loop can be a bit slower. If `async` / `await` 12281cb0ef41Sopenharmony_ciflow and speed are both essential, a mixed approach can be applied: 12291cb0ef41Sopenharmony_ci 12301cb0ef41Sopenharmony_ci```js 12311cb0ef41Sopenharmony_ciconst { once } = require('node:events'); 12321cb0ef41Sopenharmony_ciconst { createReadStream } = require('node:fs'); 12331cb0ef41Sopenharmony_ciconst { createInterface } = require('node:readline'); 12341cb0ef41Sopenharmony_ci 12351cb0ef41Sopenharmony_ci(async function processLineByLine() { 12361cb0ef41Sopenharmony_ci try { 12371cb0ef41Sopenharmony_ci const rl = createInterface({ 12381cb0ef41Sopenharmony_ci input: createReadStream('big-file.txt'), 12391cb0ef41Sopenharmony_ci crlfDelay: Infinity, 12401cb0ef41Sopenharmony_ci }); 12411cb0ef41Sopenharmony_ci 12421cb0ef41Sopenharmony_ci rl.on('line', (line) => { 12431cb0ef41Sopenharmony_ci // Process the line. 12441cb0ef41Sopenharmony_ci }); 12451cb0ef41Sopenharmony_ci 12461cb0ef41Sopenharmony_ci await once(rl, 'close'); 12471cb0ef41Sopenharmony_ci 12481cb0ef41Sopenharmony_ci console.log('File processed.'); 12491cb0ef41Sopenharmony_ci } catch (err) { 12501cb0ef41Sopenharmony_ci console.error(err); 12511cb0ef41Sopenharmony_ci } 12521cb0ef41Sopenharmony_ci})(); 12531cb0ef41Sopenharmony_ci``` 12541cb0ef41Sopenharmony_ci 12551cb0ef41Sopenharmony_ci## TTY keybindings 12561cb0ef41Sopenharmony_ci 12571cb0ef41Sopenharmony_ci<table> 12581cb0ef41Sopenharmony_ci <tr> 12591cb0ef41Sopenharmony_ci <th>Keybindings</th> 12601cb0ef41Sopenharmony_ci <th>Description</th> 12611cb0ef41Sopenharmony_ci <th>Notes</th> 12621cb0ef41Sopenharmony_ci </tr> 12631cb0ef41Sopenharmony_ci <tr> 12641cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Backspace</kbd></td> 12651cb0ef41Sopenharmony_ci <td>Delete line left</td> 12661cb0ef41Sopenharmony_ci <td>Doesn't work on Linux, Mac and Windows</td> 12671cb0ef41Sopenharmony_ci </tr> 12681cb0ef41Sopenharmony_ci <tr> 12691cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Delete</kbd></td> 12701cb0ef41Sopenharmony_ci <td>Delete line right</td> 12711cb0ef41Sopenharmony_ci <td>Doesn't work on Mac</td> 12721cb0ef41Sopenharmony_ci </tr> 12731cb0ef41Sopenharmony_ci <tr> 12741cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>C</kbd></td> 12751cb0ef41Sopenharmony_ci <td>Emit <code>SIGINT</code> or close the readline instance</td> 12761cb0ef41Sopenharmony_ci <td></td> 12771cb0ef41Sopenharmony_ci </tr> 12781cb0ef41Sopenharmony_ci <tr> 12791cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>H</kbd></td> 12801cb0ef41Sopenharmony_ci <td>Delete left</td> 12811cb0ef41Sopenharmony_ci <td></td> 12821cb0ef41Sopenharmony_ci </tr> 12831cb0ef41Sopenharmony_ci <tr> 12841cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>D</kbd></td> 12851cb0ef41Sopenharmony_ci <td>Delete right or close the readline instance in case the current line is empty / EOF</td> 12861cb0ef41Sopenharmony_ci <td>Doesn't work on Windows</td> 12871cb0ef41Sopenharmony_ci </tr> 12881cb0ef41Sopenharmony_ci <tr> 12891cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>U</kbd></td> 12901cb0ef41Sopenharmony_ci <td>Delete from the current position to the line start</td> 12911cb0ef41Sopenharmony_ci <td></td> 12921cb0ef41Sopenharmony_ci </tr> 12931cb0ef41Sopenharmony_ci <tr> 12941cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>K</kbd></td> 12951cb0ef41Sopenharmony_ci <td>Delete from the current position to the end of line</td> 12961cb0ef41Sopenharmony_ci <td></td> 12971cb0ef41Sopenharmony_ci </tr> 12981cb0ef41Sopenharmony_ci <tr> 12991cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>Y</kbd></td> 13001cb0ef41Sopenharmony_ci <td>Yank (Recall) the previously deleted text</td> 13011cb0ef41Sopenharmony_ci <td>Only works with text deleted by <kbd>Ctrl</kbd>+<kbd>U</kbd> or <kbd>Ctrl</kbd>+<kbd>K</kbd></td> 13021cb0ef41Sopenharmony_ci </tr> 13031cb0ef41Sopenharmony_ci <tr> 13041cb0ef41Sopenharmony_ci <td><kbd>Meta</kbd>+<kbd>Y</kbd></td> 13051cb0ef41Sopenharmony_ci <td>Cycle among previously deleted texts</td> 13061cb0ef41Sopenharmony_ci <td>Only available when the last keystroke is <kbd>Ctrl</kbd>+<kbd>Y</kbd> or <kbd>Meta</kbd>+<kbd>Y</kbd></td> 13071cb0ef41Sopenharmony_ci </tr> 13081cb0ef41Sopenharmony_ci <tr> 13091cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>A</kbd></td> 13101cb0ef41Sopenharmony_ci <td>Go to start of line</td> 13111cb0ef41Sopenharmony_ci <td></td> 13121cb0ef41Sopenharmony_ci </tr> 13131cb0ef41Sopenharmony_ci <tr> 13141cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>E</kbd></td> 13151cb0ef41Sopenharmony_ci <td>Go to end of line</td> 13161cb0ef41Sopenharmony_ci <td></td> 13171cb0ef41Sopenharmony_ci </tr> 13181cb0ef41Sopenharmony_ci <tr> 13191cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>B</kbd></td> 13201cb0ef41Sopenharmony_ci <td>Back one character</td> 13211cb0ef41Sopenharmony_ci <td></td> 13221cb0ef41Sopenharmony_ci </tr> 13231cb0ef41Sopenharmony_ci <tr> 13241cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>F</kbd></td> 13251cb0ef41Sopenharmony_ci <td>Forward one character</td> 13261cb0ef41Sopenharmony_ci <td></td> 13271cb0ef41Sopenharmony_ci </tr> 13281cb0ef41Sopenharmony_ci <tr> 13291cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>L</kbd></td> 13301cb0ef41Sopenharmony_ci <td>Clear screen</td> 13311cb0ef41Sopenharmony_ci <td></td> 13321cb0ef41Sopenharmony_ci </tr> 13331cb0ef41Sopenharmony_ci <tr> 13341cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>N</kbd></td> 13351cb0ef41Sopenharmony_ci <td>Next history item</td> 13361cb0ef41Sopenharmony_ci <td></td> 13371cb0ef41Sopenharmony_ci </tr> 13381cb0ef41Sopenharmony_ci <tr> 13391cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>P</kbd></td> 13401cb0ef41Sopenharmony_ci <td>Previous history item</td> 13411cb0ef41Sopenharmony_ci <td></td> 13421cb0ef41Sopenharmony_ci </tr> 13431cb0ef41Sopenharmony_ci <tr> 13441cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>-</kbd></td> 13451cb0ef41Sopenharmony_ci <td>Undo previous change</td> 13461cb0ef41Sopenharmony_ci <td>Any keystroke that emits key code <code>0x1F</code> will do this action. 13471cb0ef41Sopenharmony_ci In many terminals, for example <code>xterm</code>, 13481cb0ef41Sopenharmony_ci this is bound to <kbd>Ctrl</kbd>+<kbd>-</kbd>.</td> 13491cb0ef41Sopenharmony_ci </tr> 13501cb0ef41Sopenharmony_ci <tr> 13511cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>6</kbd></td> 13521cb0ef41Sopenharmony_ci <td>Redo previous change</td> 13531cb0ef41Sopenharmony_ci <td>Many terminals don't have a default redo keystroke. 13541cb0ef41Sopenharmony_ci We choose key code <code>0x1E</code> to perform redo. 13551cb0ef41Sopenharmony_ci In <code>xterm</code>, it is bound to <kbd>Ctrl</kbd>+<kbd>6</kbd> 13561cb0ef41Sopenharmony_ci by default.</td> 13571cb0ef41Sopenharmony_ci </tr> 13581cb0ef41Sopenharmony_ci <tr> 13591cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>Z</kbd></td> 13601cb0ef41Sopenharmony_ci <td>Moves running process into background. Type 13611cb0ef41Sopenharmony_ci <code>fg</code> and press <kbd>Enter</kbd> 13621cb0ef41Sopenharmony_ci to return.</td> 13631cb0ef41Sopenharmony_ci <td>Doesn't work on Windows</td> 13641cb0ef41Sopenharmony_ci </tr> 13651cb0ef41Sopenharmony_ci <tr> 13661cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>W</kbd> or <kbd>Ctrl</kbd> 13671cb0ef41Sopenharmony_ci +<kbd>Backspace</kbd></td> 13681cb0ef41Sopenharmony_ci <td>Delete backward to a word boundary</td> 13691cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>Backspace</kbd> Doesn't 13701cb0ef41Sopenharmony_ci work on Linux, Mac and Windows</td> 13711cb0ef41Sopenharmony_ci </tr> 13721cb0ef41Sopenharmony_ci <tr> 13731cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>Delete</kbd></td> 13741cb0ef41Sopenharmony_ci <td>Delete forward to a word boundary</td> 13751cb0ef41Sopenharmony_ci <td>Doesn't work on Mac</td> 13761cb0ef41Sopenharmony_ci </tr> 13771cb0ef41Sopenharmony_ci <tr> 13781cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>Left arrow</kbd> or 13791cb0ef41Sopenharmony_ci <kbd>Meta</kbd>+<kbd>B</kbd></td> 13801cb0ef41Sopenharmony_ci <td>Word left</td> 13811cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>Left arrow</kbd> Doesn't work 13821cb0ef41Sopenharmony_ci on Mac</td> 13831cb0ef41Sopenharmony_ci </tr> 13841cb0ef41Sopenharmony_ci <tr> 13851cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>Right arrow</kbd> or 13861cb0ef41Sopenharmony_ci <kbd>Meta</kbd>+<kbd>F</kbd></td> 13871cb0ef41Sopenharmony_ci <td>Word right</td> 13881cb0ef41Sopenharmony_ci <td><kbd>Ctrl</kbd>+<kbd>Right arrow</kbd> Doesn't work 13891cb0ef41Sopenharmony_ci on Mac</td> 13901cb0ef41Sopenharmony_ci </tr> 13911cb0ef41Sopenharmony_ci <tr> 13921cb0ef41Sopenharmony_ci <td><kbd>Meta</kbd>+<kbd>D</kbd> or <kbd>Meta</kbd> 13931cb0ef41Sopenharmony_ci +<kbd>Delete</kbd></td> 13941cb0ef41Sopenharmony_ci <td>Delete word right</td> 13951cb0ef41Sopenharmony_ci <td><kbd>Meta</kbd>+<kbd>Delete</kbd> Doesn't work 13961cb0ef41Sopenharmony_ci on windows</td> 13971cb0ef41Sopenharmony_ci </tr> 13981cb0ef41Sopenharmony_ci <tr> 13991cb0ef41Sopenharmony_ci <td><kbd>Meta</kbd>+<kbd>Backspace</kbd></td> 14001cb0ef41Sopenharmony_ci <td>Delete word left</td> 14011cb0ef41Sopenharmony_ci <td>Doesn't work on Mac</td> 14021cb0ef41Sopenharmony_ci </tr> 14031cb0ef41Sopenharmony_ci</table> 14041cb0ef41Sopenharmony_ci 14051cb0ef41Sopenharmony_ci[EOF character]: https://en.wikipedia.org/wiki/End-of-file#EOF_character 14061cb0ef41Sopenharmony_ci[Readable]: stream.md#readable-streams 14071cb0ef41Sopenharmony_ci[TTY]: tty.md 14081cb0ef41Sopenharmony_ci[TTY keybindings]: #tty-keybindings 14091cb0ef41Sopenharmony_ci[Writable]: stream.md#writable-streams 14101cb0ef41Sopenharmony_ci[`'SIGCONT'`]: #event-sigcont 14111cb0ef41Sopenharmony_ci[`'SIGTSTP'`]: #event-sigtstp 14121cb0ef41Sopenharmony_ci[`'line'`]: #event-line 14131cb0ef41Sopenharmony_ci[`fs.ReadStream`]: fs.md#class-fsreadstream 14141cb0ef41Sopenharmony_ci[`process.stdin`]: process.md#processstdin 14151cb0ef41Sopenharmony_ci[`process.stdout`]: process.md#processstdout 14161cb0ef41Sopenharmony_ci[`rl.close()`]: #rlclose 14171cb0ef41Sopenharmony_ci[reading files]: #example-read-file-stream-line-by-line 1418