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

Feature request: Question comment #1074

Open
GHNewbiee opened this issue Jan 2, 2022 · 4 comments
Open

Feature request: Question comment #1074

GHNewbiee opened this issue Jan 2, 2022 · 4 comments

Comments

@GHNewbiee
Copy link

GHNewbiee commented Jan 2, 2022

The case
a) After answering a question, some following questions may have not to be asked.
b) In that case, I need to display a message, right after the answer and before the next question is asked, informing the user about those questions that will not be asked, etc.

The problem

  • For a), when is used to by-pass questions
  • For b), if no other question object function property cannot be used (*) a comment property might be added

Remark(*): I have tried to write in console through a filter or transformer function, but it failed.

Example

import inquirer from "inquirer";

inquirer
  .prompt([
    {
      type: 'confirm',
      name: 'fruit',
      message: 'Is it a fruit?',
      default: true,
      comment: input => input ? 'Question "sweet" is omitted!' : '',
    },
    {
      type: 'confirm',
      name: 'sweet',
      message: 'Is it sweet?',
      default: true,
      when: answers => answers.fruit ? false : true,
    },
    {
      type: 'confirm',
      name: 'example',
      message: 'Is it a good example?',
      default: true,
    }
  ])
  .then(() => {
    ...
  })
? Is it a fruit? Yes
Question "sweet" is omitted!
? is it a good example? Y/n
...

Tia

@GHNewbiee
Copy link
Author

Next workarounds would be used to by-pass this issue, although both are not so elegant.

  • prefix of the next question (if exists), or
  • within then() (when it's the last question)

A form of a question is like:

  • prefix <the space before question>
  • message <the question>
  • suffix <the space after question and before answer ie the space between question and answer>
  • answer

It makes sense that one would assume that also <the space after answer> should exist and is missing; that could be the comment or any other name.

  • comment <the space after answer>

If a new property does not break backward compatibility, then comment (string|function) would be added.

Tia

@GHNewbiee
Copy link
Author

Other names could be: epilogue, afterword, postscript, ps, coda, codicil, appendix, supplement, addendum

@comatory
Copy link

I have the same need but I would actually like to display something before question is asked 😆 . It's too long to be part of "prefix".

It would be great to have some kind of support for scenarios where you need to output something to output between questions.

@SBoudrias
Copy link
Owner

@comatory could you just console.log before calling inquirer.prompt (and maybe just split in 2 prompt calls)?

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