paperdave / various

Various libraries and applications related to TypeScript. Everything is contained in a monorepo to improve productivity and reduce boilerplate.
MIT License
29 stars 3 forks source link

logger: Prompting the user #25

Open BergerAPI opened 2 years ago

BergerAPI commented 2 years ago

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:

Examples can be found on the mentioned NPM-Package.

paperdave commented 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.

paperdave commented 2 years ago

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.

paperdave commented 2 years ago

[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.