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

Confirm dialog appends yes message when aborted #375

Open
eps1lon opened this issue Nov 22, 2022 · 2 comments
Open

Confirm dialog appends yes message when aborted #375

eps1lon opened this issue Nov 22, 2022 · 2 comments

Comments

@eps1lon
Copy link

eps1lon commented Nov 22, 2022

Describe the bug

When a prompt is aborted, the confirm message will read "[mesage] ... yes" which is slightly confusing since the value for that prompt will be "empty" (undefined).

To Reproduce

Steps to reproduce the behavior:

Prompt:

const { requestConfirmed } = await prompts({
        type: "confirm",
        name: "requestConfirmed",
        message: `Really`,
        initial: true,
      });

if (requestConfirmed) {
  // never reached upon abort
}
  1. Start script
  2. Abort with CTRL+C

Expected behavior

Either it displays the "no message" since that's closer to how JS would behave for implicit type conversions (Boolean(undefined) === false) or add an option to define the message for aborted confirm dialogs.

System

  • OS: MacOS 12.6
  • Terminal: ZSH
  • Node version: 14.18.2

Additional context

Add any other context about the problem here.

@joeykilpatrick
Copy link
Contributor

I think there's a broader discussion to be had here. What should be displayed on abort? Here's what's happening today:

For prompts with an initial value, that value is printed.

{
  type: 'text',
  name: 'twitter',
  message: `What's your twitter handle?`,
  initial: `terkelg`,
}
...
✖ What's your twitter handle? … terkelg
{
  type: 'password',
  name: 'secret',
  message: 'Tell me a secret',
  initial: 'INITIAL'
}
...
✖ Tell me a secret … *******
{
  type: 'select',
  name: 'actor',
  message: 'Pick your favorite actor',
  initial: 0,
  choices: [
    { title: 'Cage' },
    { title: 'Gyllenhaal' },
  ],
}
...
✖ Pick your favorite actor › Cage

For those without initial values, nothing is printed.

{
  type: 'number',
  name: 'age',
  message: 'How old are you?',
}
...
✖ How old are you? … 

In the provided example for a confirm prompt, the initial value is set to true so "yes" is printed. If the initial value is false, then "no" is printed. Since the default initial value is false if one is not provided, then you still get "no" if you don't specify.

This behavior seems unintuitive. I would be in favor of always printing no value on abort for all prompt types like in the number example above. I would happy to submit a PR.

@terkelg

@terkelg
Copy link
Owner

terkelg commented Dec 20, 2022

I agree @joeykilpatrick. Thank you

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

3 participants