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

Automatic Non-Interaction Default #51

Closed
srcspider opened this issue Mar 6, 2018 · 2 comments
Closed

Automatic Non-Interaction Default #51

srcspider opened this issue Mar 6, 2018 · 2 comments

Comments

@srcspider
Copy link

Very often when adding these sort of prompts there's one requirement that always pops up, and that's the ability to turn them off.

Usually it's cases such as trying to get things to automate and questions like "Re-build?" that get in the way. Or it can be just a case of "well I just want to run with defaults, don't want to sit here waiting for the next prompt" (with regard to why not ask upfront, it's because sometimes you dont know the options, the "default" may be just "first of available" or some such logic)

How about having the ability to timeout to a noninteraction default value?

const response = await prompts({
    type: 'number',
    name: 'value',
    message: 'How old are you?',

    // a function is prefered, but in this case just "16" would have been fine too
    assume: () => 16, 
    timeout: 4000,

    // basically: disable entirely, defaults to assume value
    // convenient if you have some --auto or --non-interactive flag already present
    off: some_boolean_variable_or_function 
});

Behavior would be:

  • if the shell is detected to be non-interactive then the noninteraction value is just instantly applied
  • if any sort of interaction happens then the noninteraction timeout disabled completely
  • there are some checks for the interaction to be meaningful (garbage characters or signals are treated as just noise)
  • a small countdown appears when it's in the last 3s before it just triggers non-interaction
Repository owner deleted a comment from tunnckoCore Mar 6, 2018
@terkelg
Copy link
Owner

terkelg commented Mar 6, 2018

Hi @srcspider. Thanks for the suggestion. I think this is similar to #47 and #22. I'm working on better handling of default values. In the future it might be possible to programmatically resolve/reject prompts in their onState callback. There's also most likely going to be a validate function that allows similar functionality (#2)

@terkelg terkelg closed this as completed Mar 6, 2018
@srcspider
Copy link
Author

srcspider commented Mar 7, 2018

Thanks the quick reply @terkelg

But just want to emphasize, since all 3 of the issues you linked don't directly mention or imply it as much. The most important part (for me) is that it needs to be "robot friendly." In other words turning any script that uses the library into a completely automated one should be super easy.

Robots can't spam enter. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants