Skip to content

createTerminalPrompter

Generated reference page for the createTerminalPrompter function export.

Signatures

ts
function createTerminalPrompter(read: ReadFn, write: WriteFn): PromptEngine;
ParameterTypeDescription
readReadFnLine reader function (returns null on EOF)
writeWriteFnOutput writer function

Members

Members

createTerminalPrompter

Create a prompt engine backed by line-based terminal I/O.

Uses a ReadFn for input and a WriteFn for output. This is the built-in renderer — sufficient for most CLI use cases. For richer TUI experiences, users can implement PromptEngine with a library like @clack/prompts or inquirer.

The prompter does not use raw mode — all input is line-based. This keeps the implementation portable across Node, Bun, and Deno without platform-specific stdin configuration.

ts
(read: ReadFn, write: WriteFn): PromptEngine;

Examples

ts
import { createInterface } from 'readline';

const rl = createInterface({ input: process.stdin, output: process.stdout });
const read = () => new Promise<string | null>((resolve) => {
  rl.question('', (answer) => resolve(answer));
});
const write: WriteFn = (s) => process.stdout.write(s);

const prompter = createTerminalPrompter(read, write);

See Also

Released under the MIT License.