Class: ReadlineInterface
A readline interface for interactive line editing.
Supports full line editing with Emacs-style key bindings, history navigation, tab completion, and syntax colorization when connected to a terminal. Falls back to simple line-buffered input for non-TTY streams.
Constructors
Constructor
new ReadlineInterface():
ReadlineInterface
Returns
ReadlineInterface
Properties
cursor
readonlycursor:number
The current cursor position in the line buffer (read-only).
history
history:
string[]
The history array. Can be read or replaced.
line
readonlyline:string
The current line buffer (read-only).
multiline
multiline:
boolean
Whether multiline mode is enabled.
Methods
[asyncIterator]()
[asyncIterator]():
AsyncIterableIterator<string>
Async iterator that yields lines until EOF or close.
Returns
AsyncIterableIterator<string>
addHistoryEntry()
addHistoryEntry(
entry):void
Add an entry to the history.
The entry is trimmed and deduplicated against the last history entry.
Parameters
entry
string
The history entry to add.
Returns
void
clearLine()
clearLine():
void
Clear the current line on the terminal. No-op if not a terminal.
Returns
void
close()
close():
void
Close the interface.
Restores terminal mode, releases stream locks, and resolves any pending
readline with null. Ends async iteration.
Returns
void
moveCursor()
moveCursor(
dx):void
Move the cursor by a delta on the terminal.
Parameters
dx
number
Number of positions to move (positive = right, negative = left).
Returns
void
question()
question(
prompt):Promise<string>
Display a one-shot prompt and read a line.
Like readline but temporarily overrides the prompt string.
Parameters
prompt
string
The prompt to display.
Returns
Promise<string>
readline()
readline():
Promise<string>
Read a single line from input.
Displays the configured prompt and waits for the user to submit a line.
Returns null on EOF (Ctrl+D on empty line) or after close is called.
Returns
Promise<string>
write()
write(
text):void
Write text to the output stream.
Parameters
text
string
The text to write.
Returns
void