-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(prompt): progress indicator for filter and validate with optiona… (
#1002) Co-authored-by: Kim Brandwijk <kim.brandwijk@gmail.com> Co-authored-by: Simon Boudrias <admin@simonboudrias.com>
- Loading branch information
1 parent
0053e3f
commit 6717092
Showing
5 changed files
with
305 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Filter and validate progress example | ||
*/ | ||
|
||
'use strict'; | ||
const inquirer = require('..'); | ||
|
||
/* eslint-disable no-promise-executor-return */ | ||
|
||
const questions = [ | ||
{ | ||
type: 'input', | ||
name: 'first_question', | ||
message: 'Question with filtering and validating text', | ||
validate: async () => { | ||
await new Promise((r) => setTimeout(r, 3000)); | ||
return true; | ||
}, | ||
filter: async (answer) => { | ||
await new Promise((r) => setTimeout(r, 3000)); | ||
return `filtered${answer}`; | ||
}, | ||
filteringText: 'Filtering your answer...', | ||
validatingText: 'Validating what you wrote...', | ||
}, | ||
{ | ||
type: 'input', | ||
name: 'second_question', | ||
message: 'Question without filtering and validating text', | ||
validate: async () => { | ||
await new Promise((r) => setTimeout(r, 3000)); | ||
return true; | ||
}, | ||
filter: async (answer) => { | ||
await new Promise((r) => setTimeout(r, 3000)); | ||
return `filtered${answer}`; | ||
}, | ||
}, | ||
]; | ||
|
||
inquirer.prompt(questions).then((answers) => { | ||
console.log(JSON.stringify(answers, null, ' ')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.