Skip to content

Commit

Permalink
feat: add completer option to forward to readline (#51)
Browse files Browse the repository at this point in the history
Author: @131

This is a rebase of #28 with the test
removed.  Testing this requires installing an entirely new pseudo-tty
library, and given that the other flags aren't tested that seems like a
lot to ask at this point.  We need to readdress testing in general in
this repo but this PR is not the place to do it.

Co-authored-by: François Leurent <131.php@cloudyks.org>
  • Loading branch information
wraithgar and 131 committed Apr 13, 2023
1 parent f30fe66 commit c149cf9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -29,6 +29,7 @@ Every option is optional.
* `terminal` Treat the output as a TTY, whether it is or not.
* `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

If silent is true, and the input is a TTY, then read will set raw
mode, and read character by character.
Expand Down
3 changes: 2 additions & 1 deletion lib/read.js
Expand Up @@ -5,6 +5,7 @@ module.exports = async function read ({
default: def = '',
input = process.stdin,
output = process.stdout,
completer,
prompt = '',
silent,
timeout,
Expand Down Expand Up @@ -35,7 +36,7 @@ module.exports = async function read ({
output = m

return new Promise((resolve, reject) => {
const rl = readline.createInterface({ input, output, terminal })
const rl = readline.createInterface({ input, output, terminal, silent: true, completer })
const timer = timeout && setTimeout(() => onError(new Error('timed out')), timeout)

output.unmute()
Expand Down

0 comments on commit c149cf9

Please sign in to comment.