bare-readline
Line editing for interactive CLIs with command history
bare-readline — Line editing for interactive CLIs with command history.
Mirrors the Node.js readline module.
npm i bare-readlineUsage
const readline = require('bare-readline')
const rl = readline.createInterface({
input: stream,
output: stream
})
rl.on('data', (line) => {
console.log(line)
rl.prompt()
}).prompt()API
Readline
new Readline(opts?: ReadlineOptions)
Source
Create a Readline interface over an input and output stream.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ReadlineOptions | — | Options; input and output are the streams to read from and render to, prompt defaults to '> ', and crlfDelay defaults to 100. |
clearLine(): string
Source
Clear the current input line from the output and reset the line buffer and cursor, returning the cleared line.
Returns string — the input line that was cleared, before the buffer and cursor were reset.
close(): void
Source
Stop listening for input and end the stream.
cursor: number
Source
The current cursor position within the input line.
getPrompt(): string
Source
Returns the current prompt string.
Returns string — the current prompt string.
input: Readable
Source
The readable stream that keystrokes are read from.
line: string
Source
The current, in-progress input line.
output: Writable
Source
The writable stream that the prompt and line edits are rendered to.
prompt(): void
Source
Render the prompt and current input line to the output.
Readline.constants: { EOL: string }
Source
Constants used by Readline, including the end-of-line sequence.
Readline.createInterface(opts?: ReadlineOptions): Readline
Source
Create a Readline interface over an input and output stream.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | ReadlineOptions | — | Options; input and output are the streams to read from and render to, prompt defaults to '> ', and crlfDelay defaults to 100. |
setPrompt(prompt: string): void
Source
Set the prompt string written before the input line.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
prompt | string | — | The prompt string written before the input line. |
write(data: string): void
Source
Write data directly to the output stream.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | string | — | The data to write to the output stream. |
Types
ReadlineOptions
interface ReadlineOptions {
crlfDelay?: number
input?: Readable
output?: Writable
prompt?: string
}Options accepted when constructing a Readline interface.
ReadlineEvents
interface ReadlineEvents extends ReadableEvents {
data: [line: string]
history: [history: string[]]
line: [line: string]
}Events emitted by a Readline interface.
See also
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.