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: prefix / suffix function support #1079

Open
GHNewbiee opened this issue Jan 20, 2022 · 0 comments
Open

Feature request: prefix / suffix function support #1079

GHNewbiee opened this issue Jan 20, 2022 · 0 comments

Comments

@GHNewbiee
Copy link

The case
A wish to conditionally display the answer line separate of that of the question line.

The problem
Although suffix: '\n' can be used, sometimes it is not convenient when answer returns nothing.

Potential solution
A prefix / suffix function support will give more freedom to styling.

Example

import inquirer from "inquirer";

inquirer
  .prompt([
    {
      type: 'checkbox',
      name: 'fruits',
      message: 'Select the fruits you like:',
      default: ['apple', 'apricot', 'banana', 'mandarin', 'orange'] ,
      choices: ['apple', 'apricot', 'banana', 'mandarin', 'orange'],
      prefix: '',
      suffix: answers => answers.fruits.length === 0 ? '' : '\n  ',
    },
  ])
  .then(() => {
    ...
  })
? Select the fruits you like:
  orange
? Next question

And, instead of

? Select the fruits you like:

? Next question

next is better:

? Select the fruits you like:
? Next question

Tia

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

No branches or pull requests

2 participants