Inquirer.js: Request: message optional

Created on 31 Mar 2017  路  6Comments  路  Source: SBoudrias/Inquirer.js

I'd like to be able to style my questions with chalk on any number of lines.

For this I'd like message to be optional.

Would you accept a PR for that?

Most helpful comment

@PierBover You can style text using chalk and you can do multiple lines using the new line character. Here's an example where i do both using chalk and string interpolation.

var inquirer = require('inquirer'),
    chalk = require('chalk');
var questions = [
    {
        name: "name",
        type: "input",
        message: `${chalk.red("what's your name?")}\n${chalk.blue("i'm a chicken")}`
    },
    {
        name: "phone",
        type: "input",
        message: "what's your phone?",
        when: answers => {
            return answers.name;
        }
    }
];

var prompt = inquirer.prompt(questions);

All 6 comments

Could you explain in more details what you have in mind? And what you're trying to do

I'd like to style the question in any way I wish. For example without the > as first character, having multiple lines, multiple text styles, etc.

I understand this is out of scope for this package, so a simple solution would be to be able to omit the message and simply present the options to the user.

Well the message property can be anything. It can be multi-line and contains color. The only missing part is the question prefix who's hard-coded.

There's been a few discussion about the best way to change that. Search the issue tracker. I'm happy to merge a PR fixing this issue properly

But the message property is always styled as bold, no?

I'll check what can be done about the prefix.

@PierBover You can style text using chalk and you can do multiple lines using the new line character. Here's an example where i do both using chalk and string interpolation.

var inquirer = require('inquirer'),
    chalk = require('chalk');
var questions = [
    {
        name: "name",
        type: "input",
        message: `${chalk.red("what's your name?")}\n${chalk.blue("i'm a chicken")}`
    },
    {
        name: "phone",
        type: "input",
        message: "what's your phone?",
        when: answers => {
            return answers.name;
        }
    }
];

var prompt = inquirer.prompt(questions);

Thanks @patrick-motard for the suggestion.

I'm guessing this should be closed then.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

christav picture christav  路  5Comments

fuechter picture fuechter  路  3Comments

szul picture szul  路  5Comments

apierzch picture apierzch  路  4Comments

aydn picture aydn  路  5Comments