Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logger: Prompting the user #25

Open
BergerAPI opened this issue Aug 1, 2022 · 3 comments
Open

logger: Prompting the user #25

BergerAPI opened this issue Aug 1, 2022 · 3 comments
Labels
enhancement New feature or request @paperdave/logger

Comments

@BergerAPI
Copy link
Contributor

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.

@BergerAPI BergerAPI changed the title feat: Prompting the user logger: Prompting the user Aug 1, 2022
@paperdave
Copy link
Owner

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
Copy link
Owner

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 paperdave added @paperdave/logger enhancement New feature or request labels Aug 21, 2022
paperdave added a commit that referenced this issue Aug 26, 2022
@paperdave
Copy link
Owner

paperdave commented Aug 26, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request @paperdave/logger
Projects
None yet
Development

No branches or pull requests

2 participants