From d917c72a9c2656950e566ebe8b4da9f89f865672 Mon Sep 17 00:00:00 2001 From: JupiterPi Date: Mon, 25 Nov 2024 19:20:27 +0000 Subject: [PATCH] feat: pass history --- README.md | 1 + src/read.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6259b5f..421e26d 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Every option is optional. * `input` Readable stream to get input data from. (default `process.stdin`) * `output` Writable stream to write prompts to. (default: `process.stdout`) * `completer` Autocomplete callback (see [official api](https://nodejs.org/api/readline.html#readline_readline_createinterface_options) for details +* `history` History array, which will be appended to. If silent is true, and the input is a TTY, then read will set raw mode, and read character by character. diff --git a/src/read.ts b/src/read.ts index b14a2ad..2bd446e 100644 --- a/src/read.ts +++ b/src/read.ts @@ -16,6 +16,7 @@ export interface Options { terminal?: boolean replace?: string, completer?: Completer | AsyncCompleter, + history?: string[], } export async function read ({ @@ -29,6 +30,7 @@ export async function read ({ edit, terminal, replace, + history, }: Options): Promise { if ( typeof def !== 'undefined' && @@ -61,7 +63,7 @@ export async function read ({ output = m return new Promise((resolve, reject) => { - const rl = createInterface({ input, output, terminal, completer }) + const rl = createInterface({ input, output, terminal, completer, history }) // TODO: add tests for timeout /* c8 ignore start */ const timer = timeout && setTimeout(() => onError(new Error('timed out')), timeout)