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

Added prefix and suffix custom option #571

Merged
merged 3 commits into from
Sep 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Array values can be simple `strings`, or `objects` containing a `name` (to displ
- **filter**: (Function) Receive the user input and return the filtered value to be used inside the program. The value returned will be added to the _Answers_ hash.
- **when**: (Function, Boolean) Receive the current user answers hash and should return `true` or `false` depending on whether or not this question should be asked. The value can also be a simple boolean.
- **pageSize**: (Number) Change the number of lines that will be rendered when using `list`, `rawList`, `expand` or `checkbox`.
- **prefix**: (String) Change the default _prefix_ message.
- **suffix**: (String) Change the default _suffix_ message.

`default`, `choices`(if defined as functions), `validate`, `filter` and `when` functions can be called asynchronous. Either return a promise or use `this.async()` to get a callback you'll call with the final value.

Expand Down Expand Up @@ -375,6 +377,7 @@ Prompt for selecting index in array where add new element<br>
![inquirer-select-line gif](https://media.giphy.com/media/xUA7b1MxpngddUvdHW/giphy.gif)

[__command__](https://github.com/sullof/inquirer-command-prompt)<br>
<br>
Simple prompt with command history and dynamic autocomplete

[__inquirer-chalk-pipe__](https://github.com/LitoMore/inquirer-chalk-pipe)<br>
Expand Down
6 changes: 4 additions & 2 deletions lib/prompts/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ var Prompt = module.exports = function (question, rl, answers) {
},
when: function () {
return true;
}
},
suffix: '',
prefix: chalk.green('?')
});

// Check to make sure prompt requirements are there
Expand Down Expand Up @@ -126,7 +128,7 @@ Prompt.prototype.handleSubmitEvents = function (submit) {
*/

Prompt.prototype.getQuestion = function () {
var message = chalk.green('?') + ' ' + chalk.bold(this.opt.message) + chalk.reset(' ');
var message = this.opt.prefix + ' ' + chalk.bold(this.opt.message) + this.opt.suffix + chalk.reset(' ');

// Append the default if available, and if question isn't answered
if (this.opt.default != null && this.status !== 'answered') {
Expand Down