Skip to main content

Module readline

Module readline 

Source
Expand description

Node readline module.

  • 'line' and 'close' events, and for await (const line of rl): an Interface listens to its input stream’s 'data'/'end' — from creation, or for process.stdin from the first 'line'/'close' listener or async iterator, which sets standard input flowing (process::stdin_call). Lines split on \r\n, \n or 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) writes query to stdout and, before any line events have started, reads exactly ONE line from stdin synchronously and invokes cb(line); once they have, the answer is the next line the input delivers. readline/promises resolves a promise instead.
  • interface.write(data) writes to the output; prompt() writes the stored prompt; setPrompt/getPrompt manage 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 for instance_has_method wiring).
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/promises surface: the same module, whose createInterface builds an Interface with a promise-returning question.

Functions§

call
constant
A non-function member of the readline namespace (reachable via namespace_property IF the parent routes "readline" into stdlib::constant). readline.Interface is the interface constructor.
construct
new readline.Interface(options | input[, output]) — the class form of createInterface, 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>.