flow(function*(groupName, groupId) { const { value: name } = yield prompt('Rename group', undefined, { inputValue: groupName }); if (name) { const group = self.groups.find(g => g.id === groupId); group.setName(name); } })
test('default option defaults to false', async () => { await requestConfirmation('foo'); expect(inquirer.prompt).toHaveBeenCalledWith([ { name: 'requestConfirmation', type: 'confirm', message: 'foo', default: false, }, ]); });
// run your custom prompt enquirer.prompt({ type: 'custom-input', //<= specify your custom type to run the prompt name: 'username', message: 'What is your username?' }) .then(answers => console.log('ANSWERS:', answers)) .catch(console.error);
function askForStep() { return new Promise(((resolve) => { nextStep = resolve; rl.setPrompt(' I.', 3); rl.resume(); rl.prompt([false]); })); }
constructor (program) { this.options = program if (this.options.prompt === false) { this.options.spinner = false } }
async close() { this.state.closed = true; try { let sections = this.sections(); let lines = Math.ceil(sections.prompt.length / this.width); if (sections.rest) { this.write(ansi.cursor.down(sections.rest.length)); } this.write('\n'.repeat(lines)); } catch (err) { /* do nothing */ } this.emit('close'); }
get color() { let styles = this.prompt.styles; if (this.cancelled) return styles.cancelled; if (this.submitted) return styles.submitted; let color = this._color || styles[this.status]; return typeof color === 'function' ? color : styles.pending; }
test('basics', t => { t.plan(4); t.equal(typeof prompts, 'object'); t.equal(typeof prompt, 'function'); t.equal(typeof prompt.prompt, 'function'); t.equal(typeof prompt.inject, 'function'); });
prompt({ type: 'input', name: 'color', message: 'Favorite color?' }) .then(answers => { console.info(answers); process.exit(0); });
flow(function*(projectId, projectName) { const project = self.projects.find(({ id }) => id === projectId); if (project === undefined) return; const { value: name } = yield prompt('Rename project', undefined, { inputValue: projectName }); if (name) { project.setName(name); } })
(async() => { const answers = await prompt({ type: 'autocomplete', name: 'color', header: yosay('Welcome to my awesome generator!'), message: 'Pick your favorite colors', choices: ['aqua', 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime'] }); console.log(answers); })().catch(console.log);
instance .prompt([ { name: 'test', type: 'text', message: '' }, () => ({ name: 'test', type: 'text', message: '' }) ]) .then(answer => answer.question1);
Enquirer .prompt([ { name: 'test', type: 'text', message: '' }, () => ({ name: 'test', type: 'text', message: '' }) ]) .then(answer => answer);
(async() => { const answers = await prompt({ type: 'autocomplete', name: 'color', header: yosay('Welcome to my awesome generator!'), message: 'Pick your favorite colors', choices: ['aqua', 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime'] }); console.log(answers); })().catch(console.log);
// run your custom prompt enquirer.prompt({ type: 'custom-input', //<= specify your custom type to run the prompt name: 'username', message: 'What is your username?' }) .then(answers => console.log('ANSWERS:', answers)) .catch(console.error);