Giter Site home page Giter Site logo

enquirer / enquirer Goto Github PK

View Code? Open in Web Editor NEW
7.5K 44.0 277.0 16.15 MB

Stylish, intuitive and user-friendly prompts, for Node.js. Used by eslint, webpack, yarn, pm2, pnpm, RedwoodJS, FactorJS, salesforce, Cypress, Google Lighthouse, Generate, tencent cloudbase, lint-staged, gluegun, hygen, hardhat, AWS Amplify, GitHub Actions Toolkit, @airbnb/nimbus, and many others! Please follow Enquirer's author: https://github.com/jonschlinkert

Home Page: https://github.com/jonschlinkert

License: MIT License

JavaScript 83.63% CSS 0.27% TypeScript 1.20% SCSS 13.11% Handlebars 1.79%
prompt inquirer cli readline terminal confirm prompts yo yeoman command-line

enquirer's People

Contributors

318097 avatar adityavyas611 avatar agentender avatar ahmadawais avatar alcalzone avatar andarist avatar brentjanderson avatar camilaibs avatar danieldelcore avatar deve-sh avatar doowb avatar g-plane avatar gabel7r avatar hipstersmoothie avatar hongaar avatar imgbotapp avatar jonschlinkert avatar jounqin avatar jsonkao avatar knpwrs avatar mischah avatar ovyerus avatar pixelass avatar rajat-sr avatar satotake avatar shortercode avatar shumkov avatar swyxio avatar trysound avatar yeskunall avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

enquirer's Issues

feature: additional choice "roles"

What is a choice "role"?

Currently, a role property may optionally be defined on choices to determine how a choice will be rendered in the terminal. When defined, this property also determines whether or not the choice can be focused or enabled ("checked"). As of this writing, the only roles supported are:

  • separator
  • heading (for choice groups)

Another choice role we can support is:

  • expandable (nested choice groups that can expand/collapse)

What other roles might be useful?

It would be interesting to support additional roles on choices, like heading, which could be used to indicate that a choice should be used as a heading for a choice group.

What are your ideas? Let us know in the comments!

Allow initial to be editable

When setting initial in a form, I want it to be as if it was entered by the user. That is, I can navigate using the cursor keys and edit just the part I want to edit.

At present, if you type, the initial value disappears completely. If you type the same letters though, it sticks around. So it seems like its behaving more like a hint. This is unexpected.

how to access to 'value' in choices?

below snippet select method is return choices.name of value, but how can i access to value in choices?

const {prompt} = require("enquirer");

(async function() {
  const questions = [
    {
      type: "select",
      name: "color",
      message: "Favorite color?",
      initial: 0,
      choices: [
        {name: "red", message: "red", value: "#ff0000"}, //<= choice object
        {name: "green", message: "Green", value: "#00ff00"}, //<= choice object
        {name: "blue", message: "Blue", value: "#0000ff"} //<= choice object
      ]
    }
  ];

  let answers = await prompt(questions);

 // return choices.name
  console.log(answers.color);   // e.x { color: 'red' }  where's gone ' value ' ??
})();

Question docked at the bottom?

Is there any possible way to dock a question prompt at the bottom or at least move it upon output to the console so it does not interfere with the prompt?

Interesting, but annoying docs

I was interested, especially when I read it only takes 11ms to load. I decided to try it out by copying and pasting code from the docs:

var enquirer = require('enquirer');

enquirer.question('first', 'First name?');
enquirer.question('last', 'Last name?');

enquirer.ask('first')
  .then(function(answers) {
    console.log(answers);
  });

But no! How dare I! I get this:

enquirer.question('first', 'First name?');
         ^
TypeError: enquirer.question is not a function

I would'nt have bothered actually, I could read the docs further or take a look at the tests to see whats going on, but I have been trying to get my custom generators working using https://github.com/generate/generate, same devs, same problems, documented examples that don't work and one has no idea why.

I apologize.

Does anyone know what I am doing wrong? A code example would be nice. Thanks

Real world benchmark: saving ~150ms for Hygen

Hi all,
Hygen is next-gen code generation framework where one of the key principles is performance and developer experience.

Just wanted to FYI that in a real world replacement of inquirer with enquirer in Hygen (not pushed yet, but currently under testing) enquirer is winning ~150ms:

Before

Start time: (2018-11-11 08:13:51 UTC) [treshold=1%]
 #  module                                         time  %
 1  graceful-fs (node_mod...l-fs/graceful-fs.js)    4ms  โ–‡ 1%
 2  ./fs (node_modules/fs...tra/lib/fs/index.js)    4ms  โ–‡ 1%
 3  ./copy-sync (node_mod.../copy-sync/index.js)    3ms  โ–‡ 1%
 4  ./json (node_modules/...a/lib/json/index.js)    3ms  โ–‡ 1%
 5  fs-extra (node_module...-extra/lib/index.js)   20ms  โ–‡โ–‡โ–‡ 7%
 6  lodash (node_modules/lodash/lodash.js)         15ms  โ–‡โ–‡โ–‡ 5%
 7  yargs-parser (node_mo...rgs-parser/index.js)    3ms  โ–‡ 1%
 8  ./params (src/params.js)                       19ms  โ–‡โ–‡โ–‡ 7%
 9  ./engine (src/engine.js)                       40ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 14%
10  color-convert (node_m...or-convert/index.js)    4ms  โ–‡ 1%
11  ansi-styles (node_mod...nsi-styles/index.js)    6ms  โ–‡ 2%
12  chalk (node_modules/chalk/index.js)             9ms  โ–‡โ–‡ 3%
13  ./help (src/help.js)                            9ms  โ–‡โ–‡ 3%
14  ./index (src/index.js)                         52ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 18%
15  ./bin (src/bin.js)                             56ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 19%
16  ./json (node_modules/...yaml/schema/json.js)    4ms  โ–‡ 1%
17  ./core (node_modules/...yaml/schema/core.js)    5ms  โ–‡ 2%
18  ./schema/default_safe...ema/default_safe.js)    9ms  โ–‡โ–‡ 3%
19  esprima (node_modules...ima/dist/esprima.js)   14ms  โ–‡โ–‡โ–‡ 5%
20  ../type/js/function (...type/js/function.js)   15ms  โ–‡โ–‡โ–‡ 5%
21  ./schema/default_full...ema/default_full.js)   16ms  โ–‡โ–‡โ–‡ 5%
22  ./js-yaml/loader (nod...b/js-yaml/loader.js)   27ms  โ–‡โ–‡โ–‡โ–‡โ–‡ 9%
23  ./lib/js-yaml.js (nod...yaml/lib/js-yaml.js)   30ms  โ–‡โ–‡โ–‡โ–‡โ–‡ 10%
24  js-yaml (node_modules/js-yaml/index.js)        30ms  โ–‡โ–‡โ–‡โ–‡โ–‡ 10%
25  front-matter (node_mo...ont-matter/index.js)   31ms  โ–‡โ–‡โ–‡โ–‡โ–‡ 11%
26  ./context (src/context.js)                      3ms  โ–‡ 1%
27  ./render (src/render.js)                       36ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 12%
28  chalk (node_modules/i...ules/chalk/index.js)    3ms  โ–‡ 1%
29  ./objects/separator (...bjects/separator.js)    4ms  โ–‡ 1%
30  lodash (node_modules/...es/lodash/lodash.js)   15ms  โ–‡โ–‡โ–‡ 5%
31  ./baseUI (node_module...er/lib/ui/baseUI.js)   17ms  โ–‡โ–‡โ–‡ 6%
32  ./ui/bottom-bar (node...ib/ui/bottom-bar.js)   19ms  โ–‡โ–‡โ–‡ 7%
33  ../Subscriber (node_m...ernal/Subscriber.js)    5ms  โ–‡ 2%
34  ./util/toSubscriber (...til/toSubscriber.js)    5ms  โ–‡ 2%
35  ./internal/Observable...ernal/Observable.js)    5ms  โ–‡ 2%
36  ./internal/observable...ctableObservable.js)    4ms  โ–‡ 1%
37  ./scheduler/queue (no.../scheduler/queue.js)    3ms  โ–‡ 1%
38  ../Notification (node...nal/Notification.js)    3ms  โ–‡ 1%
39  ./operators/observeOn...rators/observeOn.js)    3ms  โ–‡ 1%
40  ./internal/ReplaySubj...al/ReplaySubject.js)    7ms  โ–‡โ–‡ 2%
41  ../util/subscribeToRe...ubscribeToResult.js)    3ms  โ–‡ 1%
42  ./internal/observable...le/combineLatest.js)    4ms  โ–‡ 1%
43  ./internal/observable...bservable/concat.js)    4ms  โ–‡ 1%
44  rxjs (node_modules/rxjs/index.js)              42ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 14%
45  rxjs/operators (node_.../operators/index.js)   46ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 16%
46  ./ui/prompt (node_mod...er/lib/ui/prompt.js)   91ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 31%
47  ../utils/screen-manag...s/screen-manager.js)    3ms  โ–‡ 1%
48  ./base (node_modules/...lib/prompts/base.js)    5ms  โ–‡ 2%
49  ./prompts/list (node_...lib/prompts/list.js)    9ms  โ–‡โ–‡ 3%
50  chardet (node_modules/chardet/index.js)         4ms  โ–‡ 1%
51  iconv-lite (node_modu...v-lite/lib/index.js)    4ms  โ–‡ 1%
52  crypto (crypto)                                 4ms  โ–‡ 1%
53  tmp (node_modules/tmp/lib/tmp.js)               6ms  โ–‡ 2%
54  external-editor (node...ditor/main/index.js)   16ms  โ–‡โ–‡โ–‡ 5%
55  ./prompts/editor (nod...b/prompts/editor.js)   17ms  โ–‡โ–‡โ–‡ 6%
56  inquirer (node_module...rer/lib/inquirer.js)  144ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 49%
Total require(): 1034
Total time: 292ms

After

Start time: (2018-11-11 08:13:02 UTC) [treshold=1%]
 #  module                                        time  %
 1  ./polyfills.js (node_...ful-fs/polyfills.js)   2ms  โ–‡ 1%
 2  graceful-fs (node_mod...l-fs/graceful-fs.js)   4ms  โ–‡โ–‡ 3%
 3  ./fs (node_modules/fs...tra/lib/fs/index.js)   5ms  โ–‡โ–‡ 3%
 4  ../mkdirs (node_modul...lib/mkdirs/index.js)   6ms  โ–‡โ–‡ 4%
 5  ./copy-sync (node_mod...y-sync/copy-sync.js)   8ms  โ–‡โ–‡โ–‡ 5%
 6  ./copy-sync (node_mod.../copy-sync/index.js)   8ms  โ–‡โ–‡โ–‡ 5%
 7  ./copy (node_modules/...ra/lib/copy/copy.js)   2ms  โ–‡ 1%
 8  ./copy (node_modules/...a/lib/copy/index.js)   2ms  โ–‡ 1%
 9  ../remove (node_modul...lib/remove/index.js)   2ms  โ–‡ 1%
10  ./empty (node_modules.../lib/empty/index.js)   2ms  โ–‡ 1%
11  ./ensure (node_module...lib/ensure/index.js)   2ms  โ–‡ 1%
12  ./json (node_modules/...a/lib/json/index.js)   2ms  โ–‡ 1%
13  fs-extra (node_module...-extra/lib/index.js)  26ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 17%
14  lodash (node_modules/lodash/lodash.js)        16ms  โ–‡โ–‡โ–‡โ–‡โ–‡ 11%
15  ./params (src/params.js)                      18ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 12%
16  ./engine (src/engine.js)                      45ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 30%
17  ./config-resolver (src/config-resolver.js)     2ms  โ–‡ 1%
18  ./conversions (node_m...vert/conversions.js)   2ms  โ–‡ 1%
19  color-convert (node_m...or-convert/index.js)   4ms  โ–‡โ–‡ 3%
20  ansi-styles (node_mod...nsi-styles/index.js)   6ms  โ–‡โ–‡ 4%
21  chalk (node_modules/chalk/index.js)            8ms  โ–‡โ–‡โ–‡ 5%
22  ./help (src/help.js)                           9ms  โ–‡โ–‡โ–‡ 6%
23  ./index (src/index.js)                        57ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 38%
24  ./bin (src/bin.js)                            61ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 40%
25  ./execute (src/execute.js)                     2ms  โ–‡ 1%
26  ejs (node_modules/ejs/lib/ejs.js)              2ms  โ–‡ 1%
27  ./json (node_modules/...yaml/schema/json.js)   4ms  โ–‡โ–‡ 3%
28  ./core (node_modules/...yaml/schema/core.js)   4ms  โ–‡โ–‡ 3%
29  ./schema/default_safe...ema/default_safe.js)   7ms  โ–‡โ–‡โ–‡ 5%
30  esprima (node_modules...ima/dist/esprima.js)  14ms  โ–‡โ–‡โ–‡โ–‡โ–‡ 9%
31  ../type/js/function (...type/js/function.js)  15ms  โ–‡โ–‡โ–‡โ–‡โ–‡ 10%
32  ./schema/default_full...ema/default_full.js)  16ms  โ–‡โ–‡โ–‡โ–‡โ–‡ 11%
33  ./js-yaml/loader (nod...b/js-yaml/loader.js)  25ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 16%
34  ./js-yaml/dumper (nod...b/js-yaml/dumper.js)   2ms  โ–‡ 1%
35  ./lib/js-yaml.js (nod...yaml/lib/js-yaml.js)  28ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 18%
36  js-yaml (node_modules/js-yaml/index.js)       28ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 18%
37  front-matter (node_mo...ont-matter/index.js)  28ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 18%
38  inflection (node_modu...n/lib/inflection.js)   2ms  โ–‡ 1%
39  ./context (src/context.js)                     3ms  โ–‡ 2%
40  ./render (src/render.js)                      34ms  โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡โ–‡ 22%
41  ./add (src/ops/add.js)                         2ms  โ–‡ 1%
42  ./lib/utils (node_mod...quirer/lib/utils.js)   2ms  โ–‡ 1%
43  enquirer (node_modules/enquirer/index.js)      4ms  โ–‡โ–‡ 3%
Total require(): 278
Total time: 152ms

windows tests

We should get appveyor running, or another CI that supports Windows. PR would be appreciated. I can handle the auth etc.

Invalid `process.stdin` stream when test with Ava

I am moving from prompts to enquirer. Previously with prompts I can use .inject to replace user input, but I don't see such method on enquirer.

This seems to become a problem with Ava because Ava runs tests in parallel, so when I try to run test with enquirer as follows:

clipped.prompt.on('prompt', (p: any) => {
  p.value = 'a2'
  p.submit()
})

const response = await clipped.prompt({
  type: 'text',
  name: 'q1',
  initial: 'a1',
  message: 'Question 1'
})
t.is(response.q1, 'a2')

It will return error Error: Invalid stream passed

todo: recipes

  • Multilingual support - show how easy it is to add support for multiple languages.
  • spinners and loading indicators
  • asynchronously loaded choices
  • chained prompts
  • using prompts as choices

What other examples would you like to See?

select: value is printed when picked instead of message

I am using a select, with functions as values:

  const { handler } = await prompt({
    name: 'handler',
    type: 'select',
    message: `Question?`,
    choices: [
      {
        message: 'A',
        value: () => {}
      },
      {
        message: 'B',
        value: () => {}
      },
      {
        message: 'C',
        value:  () => {}
      }
    ]
  });

I would expect the message to be printed after the user has picked a choice. Instead I see the function printed to console.

How to use the given prompts?

Thanks for such a dope product! ๐Ÿ’–

I tried something like:

image

... but I get this:

image

All your examples seem to pull in the prompts relatively, and so it works if I run the examples, but Iโ€™m not sure how to import them into my own project.

Obviously, Iโ€™m doing something wrong, but I guess my point is that itโ€™s not obvious how one can use the different prompts you show in your GIFs. How can we improve this?

How do recursive calls work?

Why this recursive call loot_root() can't work?

const AutoComplete = require('../../lib/prompts/autocomplete');
const yosay = require('yosay');

const prompt = new AutoComplete({
  header: yosay('What can I do for you๏ผŸ'),
  message: '=>',
  choices: ['CB']
});

const prompt2 = new AutoComplete({
  name: 'Options',
  message: '=>',
  choices: ['BACK',]
});

function loop_root() {
  prompt.run().then(answer => {
      if (answer === 'CB') {
        prompt2.run().then(answer1 => {
          if (answer1 === 'BACK') {
            // TODO can not work?
            loop_root();
          }
        }).catch(console.error);
      }
    }
  ).catch(err => console.log('ERROR:', err));
}

loop_root();

Integrating Enquirer with a browser UI?

Hello - Is it possible to integrate Enquirer with a browser UI, such that question/prompt definitions and related behaviours are decoupled from the presentation (e.g., CLI, browser)? If so, can you please guide me to the relevant documentation? If not, would you consider adding this to the roadmap?

I am not looking for a terminal-like interface in a browser, rather I'm looking for the core of Enquirer (types of inquiries, validation, etc.) and pluggable outputting functions, so that my app can be used in a terminal environment and a web app environment with minimal code.

I asked a similar question to Inquirer.js, and here is the response: SBoudrias/Inquirer.js#543

Question docked at bottom #2

Now that it is released, I must ask again:

How exactly can I make a prompt that is sort of docked at the bottom? Mainly just want any of my output to go above the prompt. I also want to have the cursor not affected by anything and able to shift everything down without the output text getting in the way of the input.

enquire.ask twice seems to hang

Something like this:

const enquirer = new Enquirer()
enquirer.ask({
  message: 'hi',
  type: 'input',
  name: 'name'
}).then(() => {
  return enquirer.ask({ ... })
})

Formatting result of autocomplete

I have been trying to format the result of an autocomplete prompt, by adding the following function:

result(value) {
    return `origin/${value}`;
}

but it doesn't seem to change anything.

I tried searching for a related issue or read the source code, but all I found is it's possible to override the format function, which will give me the result I want, but mess with the input.
I am probably missing something, so I would really appreciate any help in the matter.

prompt package names

The code is now generalized for questions and prompts (in the prompt-base and prompt-question modules).

Since all prompts can now be used with or without enquirer, should I change the naming convention of prompt modules from enquirer-prompt-* to just prompt-*?

The only npm name that's taken currently is prompt-input, but input is built into prompt-base now anyway.

I'm 50/50 on this (partially b/c I don't look forward to renaming the two or three packages I already published lol), but it seems like making them generic is the way to go - and if so, I should do it now, before I publish the other 5 or 6 modules.

thoughts? @doowb, @tunnckoCore, @TrySound?

"await" doesnt work

I install with npm i enquirer (nodejs V8.12.0)

image

i want to put this module in my project, its pretty nice !!! ๐Ÿ‘

PS : With .ts i cant go very far so now i will use enquirer with .js ๐Ÿ˜ญ
Good luck ๐Ÿ˜ƒ

deprecate v1 prompts

In the coming days we will be deprecating, then archiving, all prompts that are published as separate modules and now ship with Enquirer as of v2.0.

On all prompt plugin or util libraries

DON'T

  • remove topics

DO

  • close issues
  • close pull requests
  • update readme
  • update repo description
  • update repo url to https://github.com/enquirer/enquirer
  • deprecate the library on NPM
  • last, archive the repository

Use the following for closing issues:

Closing as this prompt has been completely refactored from the ground up, and is now included in [Enquirer 2.0](https://github.com/enquirer/enquirer). Please direct all questions, issues and feature requests to that repository.

Use the following for closing pull requests:

Closing as this prompt has been completely refactored from the ground up, and now included in [Enquirer 2.0](https://github.com/enquirer/enquirer). Please direct all questions, issues and feature requests to that repository.

Thanks for your pull request! Please consider contributing to [enquirer](https://github.com/enquirer/enquirer) instead. 

Use the following for repository descriptions for non-prompts

This repository has been archived, since it is no longer needed by Enquirer.

Use the following for repository descriptions for non-prompts

This repository was archived, as this prompt now ships with Enquirer.

Update the README to the following:

This repository has been archived, since it is no longer needed or it's functionality is included in [Enquirer v2.0](https://github.com/enquirer/enquirer).

Select prompt doesn't use initial value from function

When the initial value of a select prompt is a function, the returned value isn't used. But validated that the initial function gets called.

enquirer 2.0.7

Not working:

{
    name: 'type',
    message: 'Article type:',
    type: 'select',
    choices: ['article', 'video'],
    initial: () => 'video'
}

Working:

{
    name: 'type',
    message: 'Article type:',
    type: 'select',
    choices: ['article', 'video'],
    initial: 'video'
}

Help Wanted: Documentation

Earlier today, #24 was published as 2.0 with the beta tag! The only thing stopping us from merging to master and publishing 2.0 is documentation.

If you'd like to help with docs (readme documentation only, for now), here is an outline of what we need:

  • A section for the Enquirer class. Enquirer itself can be viewed as the prompt "runner". It handles state and events for multiple prompts, etc.
  • A section for the base Prompt class - The Prompt class creates the readline interface, handles keypress events, and other conveniences that simplify creating custom prompts. The Prompt class is inherited by every other prompt.
  • A section for each base prompt type in the lib/types directory. The types - string, number, boolean and array - are classes that can be extended to create higher level prompts. For example, the Input prompt class inherits the StringPrompt class, and the Select prompt inherits the ArrayPrompt class. This approach makes prompts extremely simple to create, extend, and customize. The type classes are just a convenience, and don't need to be use if you'd rather just extend the base Prompt class.
  • A section for each prompt in the lib/prompts directory.
  • A table or list of the available options for each prompt. Most prompts support the same global options, like message, name, etc. We can list these with the base Prompt class. Then in the docs for each prompt we only need to list the special options supported that prompt.
  • Usage examples (you can find many examples in the examples directory)

Other stuff

  • blog posts
  • tutorials
  • tweet about 2.0!

We encourage you to tell your friends and write about Enquirer! We're really excited about how awesome Enquirer 2.0 is, and we think you'll love it too!

How to chain more than one call?

Hi,
I've seen #5 but this one is slightly different (at least I think so). I find the library very nice, but I'm failing at making a simple menu with 2 screens (the 2nd screen depending on the output of the 1st), which seems like a basic use of enquirer.

So have I missed something here?
Here is my use case: I want to first ask the user for the name of an argument, and then make him chose between a predefined set of arguments (the use case for this is templating, but that doesn't matter)

Here is my code:

'use strict';

const Enquirer = require('enquirer')
const inspect = require ('util').inspect

for (let i = 3; i > 0; i--) {
    let enquirer = new Enquirer ()

    enquirer.register ('radio', require ('prompt-radio'))

    enquirer.question ('argName', 'Name for the input argument (' + i + ')?')
    enquirer.question ('argType', 'Type of argument (' + i + ')?', {
        type: 'radio',
        choices: ['STRING', 'INT32', 'BOOL']
    })

    enquirer.ask()
    .then (answers => {
        console.log ('Argument ' + i)
        console.log (inspect (answers))
        console.log ('--')
    })
}

And when I run it, I've got:

? Name for the input argument (3)? Foo
? Name for the input argument (2)? Foo
? Name for the input argument (1)? Foo
? Type of argument (3)? INT32
? Type of argument (2)? INT32
? Type of argument (1)? INT32
Argument 3
{ argName: 'Foo', argType: [ 'INT32' ] }
--
Argument 2
{ argName: 'Foo', argType: [ 'INT32' ] }
--
Argument 1
{ argName: 'Foo', argType: [ 'INT32' ] }
--

I've got the first Name input for the argument (1)?, then I answered Foo, then I was presented the radio choice, I selected INT32 with <Space> and when I pressed entered, it dumped all of this.

I did not have a second (and neither a third) choice. How can I achieve this?

Perf comparisons

Perf

Related: #39

This shows the time it takes to load the following libraries when they are required anywhere inside your project, even if the library is never used.

  • Enquirer v2.0.0 - 7ms (10 require calls)
  • Prompts v1.1.1 - 27ms (52 require calls)
  • Inquirer v6.2.0 - 253ms (775 require calls!)

Enquirer

image

Prompts

image

Inquirer

image

Windows issue

This is being logged in AppVeyor CI:

V
a
l
u
e
 
f
o
r
 
V
A
R
1
 
(
)

from this code:

const Enquirer = require('enquirer');

const test = varnames => {
  const enquirer = new Enquirer();

  const questions = varnames.map(varname => enquirer.question({
    name: varname,
    message: `Value for ${varname}`,
    default: ""
  }));

  return enquirer.ask(questions);
};

test(['VAR1','VAR2']);

I'm not sure if what I'm experiencing is caused by Enquirer or by the CI. I've tried running this library in a Windows VM and could not reproduce the issue there.

https://ci.appveyor.com/project/stevenvachon/dotenv-prompt/build/24/job/64gi24d9i6ytyxnf#L588

logo

We need a logo!!!

Validation

Awesome mod. Really love the fact it loads so quickly. I'm wondering if there's a validation option somewhere in the source that I've missed?

Like Inquirer has - if it fails validation, then an error message is displayed and the question is re-asked.

Completely possible to do this in userland, of course, but the code can quickly devolve into spaghetti when separate validation needs to be done inside every .then block, with logic to handle the re-prompt.

Apologies if I've missed this; it's not mentioned in the docs.

Multiline prompt?

Sounds like there is no such? It errors with "prompt is not registered".

Any way to imitate this?

Auto answering

The same as this issue at Inquirer.

Copied for ref:


I'm building a CLI tool that takes options via yargs. Inquirer is used to show a 'wizard' for any question that isn't already answered by a command line arg.

I can't use default, because that's basically just echoing back what the user has already entered, and is asking them to re-confirm (and if when is false, it gets ignored completely.)

I can't use when(), because that will skip the question entirely and avoid populating the answers hash for further questions, as well as miss out on the validation functions.

What would solve it is an answer field on the question object. Unlike 'default', putting a value there would avoid asking the question - BUT, it would automatically re-ask it if the value fails validation and show the usual error prompt.

So, it's basically a means to skip asking the question, but treat the value given as the answer.

Does that make sense?

code review

@TrySound if you have a moment, I'd love to have your feedback on this code in particular. Any feedback would be great, but I'm still somewhat new to promises.

(@doowb, @tunnckoCore, feedback welcome from you as well)

prs would be great too :) but I'd be happy with feedback.

Feature Suggestion: Skipping a question on condition

I'm building a series of command-line related tools and have been really please to run across this project. Previously I have been using inquirer, but have felt its weight and design decisions don't suit my goals too well. However one useful feature it has that is currently not supported here is the ability to skip a question based on previous answers.

enquirer.ask([
  {
    type: 'list',
    name: 'name',
    message: 'question?',
    // new - a function that returns a boolean value on whether or not to ask a question
    when: function (answers) {
       return answers.x === 'yes'
    })
  }
])

I've run into this need at least once building a interface for building commit messages (think commitizen) where you need to ask additional questions if a commit represents a breaking change.

Issue related to Windows mintty

OS: Window 10
Terminal: mintty 2.9.4 along with Git

(node:28480) UnhandledPromiseRejectionWarning: Error: Invalid stream passed
    at Function.keypress.listen (D:\Workspace\test\enquirer-test\node_modules\enquirer\lib\keypress.js:191:11)
    at SelectPrompt.start (D:\Workspace\test\enquirer-test\node_modules\enquirer\lib\prompt.js:158:28)
    at SelectPrompt.initialize (D:\Workspace\test\enquirer-test\node_modules\enquirer\lib\prompt.js:167:16)
    at SelectPrompt.initialize (D:\Workspace\test\enquirer-test\node_modules\enquirer\lib\types\array.js:21:17)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:695:11)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3
(node:28480) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:28480) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

BTW: Examples in this repo are running normally, this issue only happened when used through require('enquirer').

readme incorrectly references prompt-input instead of prompt-text

The README.md lists prompt-input as a possible prompt type, but that npm package is under a security hold:

This package name is not currently in use, but was formerly occupied by a popular package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.

It looks like the actual package included by default in Enquirer is prompt-text, so I'm guessing the only issue here is that the README.md needs updating, although it's also not clear if setting the type of a question to "input" will choose prompt-text.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.