Open BergerAPI opened 2 years ago
This would be interesting.
Though for this exact proposal I would like multi() to be a part of select(), as like an object that has options.
An alternative API for prompting for things could be a function similar to how inquirer
and prompts
, where you pass an object with a type
value with one of the prompt types. This is what I was initially thinking of copying except on a single question per function call.
The implementation of these should be done using the LogWidget API, and maybe by implementing a function like onKeyPress
, so stdin handling could be abstracted away for implementing the prompts. This also means all the prompt functions would be async.
note that we cannot use prompts directly as it will have issues when you call log functions while the prompt is visible. this is a small edge case that my library handles for spinners and other widgets, so by simply extending LogWidget, this behavior is automatically available.
[see the above commit, or packages/paperdave-logger/src/stdin.ts
]
here's an interesting function i wrote, only works on bun as of now. it reads one character from stdin and returns immediatly. no enter button needed. might be interesting if log widgets could specify like a this.getKey()
or some api where the widget system can handle giving a response.
To reduce the use of multiple packages, one could implement a prompt system. It should be similar to this package.
I'm suggesting following functions:
confirm(text: string)
(Simple yes/no prompt)prompt(text: string)
(Asking a question)select(text: string, choices: string[])
(Selecting a single value from a list of values)multi(text: string, choices: string[])
(Selecting multiple values from a list of values)Examples can be found on the mentioned NPM-Package.