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)writesqueryto stdout and reads exactly ONE line from stdin synchronously (std::io::stdin().read_line), then invokescb(line)with the trimmed line. This is a genuine blocking read, matching the observable result of Node’squestionfor a single prompt. - REAL:
interface.write(data)writes to stdout;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 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 returnsthis), but node-js never asynchronously emits'line'— there is no background stdin reader. Usequestionfor 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 forinstance_has_methodwiring). - 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"). - promises_
call readline.createInterface(options | input[, output])→ an Interface object.require('readline/promises').<method>.