Skip to main content

Module readline

Module readline 

Source
Expand description

Node readline module — a pragmatic, synchronous interface.

Node’s real readline is event-driven over a stream: it registers 'line', 'close', and keypress handlers and fires them asynchronously as the input stream produces data. node-js has no interactive stdin loop at this layer (the event loop drives timers/promises/I-O-thread tasks, not a live TTY reader), so this module implements the parts that CAN be honest without one:

  • REAL: interface.question(query, cb) writes query to stdout and reads exactly ONE line from stdin synchronously (std::io::stdin().read_line), then invokes cb(line) with the trimmed line. This is a genuine blocking read, matching the observable result of Node’s question for a single prompt.
  • REAL: interface.write(data) writes to stdout; 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 MODELED (documented, never faked): the asynchronous 'line'/'close' event streaming. interface.on('line', cb) accepts and stores the listener (so it is not lost and chaining returns this), but node-js never asynchronously emits 'line' — there is no background stdin reader. Use question for real line input. close()/pause()/resume() are no-ops.

An Interface is a plain object tagged @@native = "Interface" carrying the passed @@input/@@output streams (kept for fidelity; the real read/write always uses process stdin/stdout), the current @@prompt, and a hidden @@listeners object of registered event callbacks.

Constants§

INTERFACE_METHODS
Methods dispatched on an @@native = "Interface" object (reported to the parent for instance_has_method wiring).
METHODS

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").