Expand description
Node readline module.
'line'and'close'events, andfor await (const line of rl): an Interface listens to its input stream’s'data'/'end'— from creation, or forprocess.stdinfrom the first'line'/'close'listener or async iterator, which sets standard input flowing (process::stdin_call). Lines split on\r\n,\nor a lone\r, an unterminated last line is delivered at end of input, then'close'. See “line events” below for the ordering.interface.question(query, cb)writesqueryto stdout and, before any line events have started, reads exactly ONE line from stdin synchronously and invokescb(line); once they have, the answer is the next line the input delivers.readline/promisesresolves a promise instead.interface.write(data)writes to the output;prompt()writes the stored prompt;setPrompt/getPromptmanage it; the module cursor helpers (cursorTo/moveCursor/clearLine/clearScreenDown) emit the corresponding ANSI control sequences to stdout.- Not modelled: terminal mode (keypress decoding, history, line editing) —
input is read as lines whatever it is attached to — and
pause()/resume(), which return the Interface and change nothing.
An Interface is a plain object tagged @@native = "Interface" carrying the
passed @@input/@@output streams, the current @@prompt, a hidden
@@listeners object of registered event callbacks, and the @@rlid that
keys its line state.
Constants§
- INTERFACE_
METHODS - Methods dispatched on an
@@native = "Interface"object (reported to the parent forinstance_has_methodwiring). - ITERATOR_
METHODS - The async iterator
for await (const line of rl)reads: it takes the lines emitted from the moment it is created, and ends at'close'. Leaving the loop early (return()) closes the Interface, as in node. - METHODS
- PROMISES_
METHODS - The
readline/promisessurface: the same module, whosecreateInterfacebuilds an Interface with a promise-returningquestion.
Functions§
- call
- constant
- A non-function member of the
readlinenamespace (reachable vianamespace_propertyIF the parent routes"readline"intostdlib::constant).readline.Interfaceis the interface constructor. - construct
new readline.Interface(options | input[, output])— the class form ofcreateInterface, producing the same@@native = "Interface"object. Requires the parent to route"Interface"construction into this fn.- instance_
call - Dispatch a method on an Interface instance (
@@native = "Interface"). - iterator_
call - promises_
call readline.createInterface(options | input[, output])→ an Interface object.require('readline/promises').<method>.