Giter Site home page Giter Site logo

sboudrias / inquirer.js Goto Github PK

View Code? Open in Web Editor NEW
19.4K 151.0 1.3K 1.19 GB

A collection of common interactive command line user interfaces.

License: MIT License

JavaScript 52.29% TypeScript 47.71%
prompt command-line javascript-library nodejs javascript typescript cli node-js

inquirer.js's Issues

List not clearing itself from terminal

Looks like there's been a regression. When I hit an arrow key on a list prompt the previous prompt is not cleared. An nfinityC gets inserted too, so could be related to #22.

Terminal output after arrow keying up and down a couple times:

[?] Use a css preprocessor?: (Use arrow keys)
  [X] Sass 
  [ ] ConfinityC
[?] Use a css preprocessor?:                                                   
  [X] Sass 
  [ ] ConfinityC
[?] Use a css preprocessor?:                                                   
  [ ] Sass 
  [X] ConfinityC
[?] Use a css preprocessor?:                                                   
  [ ] Sass 
  [ ] Compass 
  [X] none 

UI improvements: make prompt more succinct

First, thanks for the new library. After using it I have some suggestions to simplify the prompts and make them feel less lengthy.

Prompt line spaces

Right now in Inquirer there are empty lines in between each prompt:

Set up some directories. ☛
Nested directories are fine.

Choose a css directory (default "css"): css

Choose a javascript directory (default "js"): js

Choose an image file directory (default "image"): image

Choose a webfonts directory (default "fonts"): fonts

In the last Yeoman prompt I grouped my questions together by category, and added a single empty line break between each section:

Set up some directories. ☛
Nested directories are fine.
[?] Choose a css directory: (css) 
[?] Choose a javascript directory: (js) 
[?] Choose an image file directory: (image) 
[?] Choose a webfonts directory: (fonts) 

Choose a template. ☛
[?] Choose a Jekyll site template
 d: default
 h5: HTML5 ★ Boilerplate (d) 

Removing the whitespace will allow for grouping, make the prompt seem shorter to the user, and keep possibly related information on the screen longer.

Defaults:

Currently defaults display like this:

Choose a css directory (default "css"):
// after hitting enter
Choose a css directory (default "css"): css

The word 'default' lengthens the prompt, and for me interrupts the reading flow. The previous prompt added the default after the colon:

Choose a css directory: (css)

This seems more understandable, since the default value is in the area that you are adding content to, and avoids some repetition within and between prompts. I think the quotes could be removed with no negative effects as well. If you wanted to get really fancy you could remove the parenthesis after the user hits enter, like this:

Choose a css directory: (css)
// after hitting enter
Choose a css directory: css

List help

The list choice is awesome. It includes a "use arrow keys tip" that disappears on first arrow keypress:

Use a css preprocessor?
  [X] sass
  [ ] compass
  [ ] none
(Use arrow key)

This is minor, but I think this could be made more compact by adding the tooltip after the last choice or after the prompt message:

Use a css preprocessor?
  [X] sass
  [ ] compass
  [ ] none  (Use arrow key)
// or
Use a css preprocessor?  (Use arrow keys)
  [X] sass
  [ ] compass
  [ ] none
// or even
Use a css preprocessor?  (↑↓)
  [X] sass
  [ ] compass
  [ ] none

When a generator has 10+ prompts it's essential to keep them as compact as possible to avoid overloading the user. Pages of prompts create the perception of complexity.

Thoughts?

Input type deletes line above itself

Thanks again for going through all these issues so quickly.

With the current master input type prompts add an empty line below themselves and delete the line above. For example:

Tell us a little about yourself. ☛
[?] Name: (Rob Wierzbowski) // Hit enter
[?] Name: Rob Wierzbowski
[?] Email: ([email protected]) // Hit enter

[?] Email: [email protected]
[?] GitHub Username: (robwierzbowski) // Hit enter

[?] GitHub Username: robwierzbowski
[?] Twitter Username: (@robwierzbowski) // and so forth

Get "expand list" prompt

With a series of choices hided by default. e.g.:

Conflict, what do you want to to [Ynadh]

With default option h who's expanding choices:

Conflict, what do you want to to:
  Y) Override file
  n) Don't override
  a) Abort
  d) Get diff
  h) Show help

Add theming capability

Inquirer could provide a theme functionnality allowing user to automatically setup the prompt color scheme.

I don't feel like it is super usefull, but this could allow higher level library from giving their user choice between some themes to better match their prompt theme (thinking mostly about "light" vs "dark" terminal).

Feedback?

Normalize spacing

When rendering subtext under a prompt, the spacing ain't unified between each prompt (it will vary from 1 to 2 LN). Would be better if always the same.

Event listeners warning on multiple prompts

Hello, thanks for this nice module!

When running multiple prompts, I get this warning:
"(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit."

Tests:

  var inquirer = require('inquirer');
  var prompt1 = function (callback) {
    inquirer.prompt([{
      type: 'list',
      name: 'choice',
      message: 'Select:',
      choices: ['one', 'two']
    }], function () {
      callback(callback);
    });
  };
  var prompt2 = function () {
    inquirer.prompt([{
      type: 'list',
      name: 'choice',
      message: 'Select:',
      choices: ['three', 'four']
    }], function () {});
  };
  var prompt3 = function () {
    inquirer.prompt([{
      type: 'list',
      name: 'choice',
      message: 'Select:',
      choices: ['five', 'six']
    }], function () {});
  };


  // Test 1
  prompt1(prompt1);

  // Test 2
  for (var i = 1; i < 11; i += 1) { prompt2(); }

  // Test 3
  for (var i = 1; i < 11; i += 1) { if (i % 2 === 0) { prompt2(); } else { prompt3(); } }

Nested example shows bug

node version: 0.8.1
inquirer version: 0.1.12 (note: This is what is downloaded by npm)
Issue: In nestedCall.js under examples the second question causes doubling of input letters.
Steps to reproduce:

  1. npm install inquirer.
  2. cd examples
  3. node nestedCall.js
  4. answer first question
  5. note that on answering 2nd question each letter of input is doubled (eg: booze -> bboooozzee)

Loop list prompt

When hit down on the last item it should go to the first and when hitting up on the first item it should go to the last.

Enhancement/discussion: change in flow based on answers.

As pizza.js shows things work fine as long as question flow is in a strictly linear fashion. But consider where the answer to one question affects the flow of another question. For example lets say that Node Pizza also offers calzones and subs and salads. Then a user would need to be asked what type of thing they want to order and based on that they would have a subset of questions to answer (perhaps coming back to the original series of questions to finish up/continue).

Could that be handled with some alterations to the inquirier module without adversely affecting the linear/serial flow of questions?

Unicode checkbox

Not sure if it would be feasible, but might consider using unicode symbols:

☐☑☒ though I fear these might be too small.

or just a checkmark on the chosen one and nothing on the others: ✔

or same as above, but an other symbol: ❯ ➤ ➔

Could also consider using unicode combinators:
http://unicodinator.com/#20E3 combined with ✔ makes ✔⃣ or ✖⃣

or this http://unicodinator.com/#20DD combined with ✔ makes ✔⃝ or ✖⃝

Home and End shortcut key?

I just killed a PR to add End and Home shortcut keys so a user can quickly get to the top and bottom of the list.

Would you still be interested in this feature? I realized I should have ask 1st since You're already working on a similar UX feature with #40 (comment)

I still think the Home + End shortcut could be useful.

I'll wait for a reply before adding a PR this time :-)

Make inquirer.prompt() blocking

Consider the following code

var inquirer = require('inquirer');

var prompts = [{
  name: 'test1',
  message: 'test1',
}]; 

var prompts2 = [{
  name: 'test2',
  message: 'test2'
}]; 

inquirer.prompt(prompts, function (props) {
  inquirer.prompt(prompts2);
});

Obviously in this example you would bundle the prompts into one list and only call inquirer.prompt once. This is a simplified example of something which could happen in yeoman (they use the 'async' module to ensure that the second prompt isn't called until the callback for the first one has been called).

One would expect that when the callback from the first prompt is called it would be 'safe' to call the second however that is not the case (in this example the second prompt immediately closes (as if enter was pressed). Wrapping the second prompt in a setTimeout works (showing that the problem is related to when the function is called).

I haven't managed to track down what exactly in inquirer is causing this behaviour (it could be because the second prompt call is called before the enter key is released?) but whatever it is I think it would be beneficial to implement some sort of blocking so that calls to prompt() are blocked until all previous calls have finished.

Add better error messages

Right now, I think I'll only catch missing required parameters.

We'll see with time if we need to add some stuff up.

Input appears as password when following password question

The code below is capturing a user's github username, password, and organization for automatic creation of github enterprise repos. After entering the password and pressing enter, the following question (input) appears as a password and the text of the question is replaced with the password question's text:

"use strict";
var inquirer = require("inquirer");

var questions = [
{
type: "input",
name: "git-username",
message: "What's your Github username:"
},
{
type: "password",
name: "git-password",
message: "What's your Github password:"
},
{
type: "input",
name: "git-organization",
message: "What is the name of your Github Organization:"
}
];

inquirer.prompt(questions, function(answers){
console.log(answers);
});

screen shot 2013-08-21 at 1 42 45 pm

screen shot 2013-08-21 at 1 43 39 pm
screen shot 2013-08-21 at 1 43 53 pm
screen shot 2013-08-21 at 1 44 05 pm

How should it handle long lists?

It does sound like an anti-pattern to have long lists, but there might be valid use-cases for it.

Currently when you have more items than fits the viewport they are scrolled out of it. You can of course scroll up yourself, but is there anyway to have the scroll follow the > selector?

Screenshot:

screen shot 2013-06-23 at 16 47 21

Test case:

/**
 * Checkbox list examples
 */

"use strict";
var inquirer = require("../lib/inquirer");

inquirer.prompt([
  {
    type: "checkbox",
    message: "Select toppings",
    name: "toppings",
    choices: [
      {
        name: "1"
      },
      {
        name: "2"
      },
      {
        name: "3"
      },
      {
        name: "4"
      },
      {
        name: "5"
      },
      {
        name: "6"
      },
      {
        name: "7"
      },
      {
        name: "8"
      },
      {
        name: "9"
      },
      {
        name: "10"
      },
      {
        name: "11"
      },
      {
        name: "12"
      },
      {
        name: "13"
      },
      {
        name: "14"
      },
      {
        name: "15"
      },
      {
        name: "16"
      },
      {
        name: "17"
      },
      {
        name: "18"
      },
      {
        name: "19"
      },
      {
        name: "20"
      },
      {
        name: "21"
      },
      {
        name: "22"
      },
      {
        name: "23"
      },
      {
        name: "24"
      },
      {
        name: "25"
      },
      {
        name: "26"
      },
      {
        name: "27"
      },
      {
        name: "28"
      },
      {
        name: "29"
      },
      {
        name: "30"
      },
      {
        name: "31"
      },
      {
        name: "32"
      },
      {
        name: "33"
      },
      {
        name: "34"
      },
      {
        name: "35"
      },
      {
        name: "36"
      },
      {
        name: "37"
      },
      {
        name: "38"
      },
      {
        name: "39"
      },
      {
        name: "40"
      }
    ],
    validate: function( answer ) {
      if ( answer.length < 1 ) {
        return "You must choose at least one topping.";
      }
      return true;
    }
  }
], function( answers ) {
  console.log( JSON.stringify(answers, null, "  ") );
});

// @passy @stephenplusplus

Remove default suffix for prompts

I'd like to discuss whether the a default suffix for prompts is helpful. generator-generator for example has a lot of its prompts in form of a question, so there's no need to append a colon:

screenshot from 2013-06-11 21 46 40

I would like to know what others think about this. :)

Validate not being checked on list prompt

I have a list prompt that has options that are dependent on setting data elsewhere. It would come very handy if validate function would be checked on prompt selection.

Keyboard input on list prompt

Two small issues:

Currently on a list prompt you can enter characters:

Use a css preprocessor?
  [X] sass
  [ ] compass
  [ ] none
(Use arrow key)this and that compass etc // <- added while selecting prompt

Hiding keyboard input would help avoid any confusion as to how you select an option in a list prompt.

Also, typing any non-alpha or arrow key crashes Inquirer and the Yeoman generator:

// typed '.'
Use a css preprocessor?
  [ ] sass
  [ ] compass
  [X] none
.
/Users/robw/wwwe/node_modules/generator-jekyllrb/node_modules/yeoman-generator/node_modules/inquirer/lib/prompts/list.js:105
  if (key.name === "up" && (this.selected - 1) >= 0) {
         ^
TypeError: Cannot read property 'name' of undefined
    at Prompt.onKeypress (/Users/robw/wwwe/node_modules/generator-jekyllrb/node_modules/yeoman-generator/node_modules/inquirer/lib/prompts/list.js:105:10)
    at EventEmitter.emit (events.js:98:17)
    at ReadStream.<anonymous> (/Users/robw/wwwe/node_modules/generator-jekyllrb/node_modules/yeoman-generator/node_modules/inquirer/lib/inquirer.js:57:14)
    at ReadStream.EventEmitter.emit (events.js:117:20)
    at emitKey (readline.js:1089:12)
    at ReadStream.onData (readline.js:834:14)
    at ReadStream.EventEmitter.emit (events.js:95:17)
    at ReadStream.<anonymous> (_stream_readable.js:720:14)
    at ReadStream.EventEmitter.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:392:10)

Thanks!

Buggy on windows

I'm using windows 8.

var inquirer = require('inquirer');

var prompts = [{
  name: 'test',
  message: 'Enter a test value',
  type: 'list',
  choices: ['Option 1', 'Option 2', 'Option 3']
}]; 

inquirer.prompt(prompts, function (props) {})

This renders as expected but you can't interact with it. (output isn't muted)

To get around it I have to hit enter first which is pretty annoying. This also causes the clean() to leave a line.

Control backspace

When backspace is pressed, the current line is completly removed and we go back to a default > prompt...

Line return may prevent full cleaning of a prompt (Unix)

When rerendering a prompt with answers or feedback, if there's a line return (because the text is to long to fit on a single line), the previous prompt won't be completely cleaned up. This leave the appearance of a display bug.

Impossible to set a default value in a list

I use a list with several choices, I'd like to pre-check one of them (which is not always the first one), so I use default, as I used to, in previous prompt in yeoman.

But it doesn't work anymore, the first choice is always set, whatever the value indicated into default.
Even if default is not set, the first choice is pre-set (which conflicts with doc of Inquirer btw, as it's impossible to set nothing in a list, as the first one is always set)

It would be nice to be able to pre-set the choice in the list (and in rawlist I guess)

Implement a queue system or throw an error when `prompt` is called before previous one has ended.

Migrated from #62 (separate issue that was brought up)

Test case

var inquirer = require('inquirer');

for (var i = 1; i < 5; i += 1) {
  inquirer.prompt([{
    type: 'list',
    name: 'choice',
    message: 'Select:',
    choices: ['one', 'two']
  }]);
}

Currently this just breaks inquirer.

I can't think of any reason why someone would need to call prompt like this as you should just pass multiple questions to prompt and if you need to split it up (you need to calculate some questions based on previous answers and the calculation includes async calls so when will not work) then you would need to do it the proper way (from within the callback).

I propose two options:

Option 1

Throw an error if inquirer.prompt is called before a previous call has finished (removed event listeners and called callback).

Option 2

Implement a queue: https://github.com/pull-requests/Inquirer.js/compare/queue

This isn't currently working properly (some tests hang - not sure why), but you get the general idea.

Option 1 would be dead simple to implement and I feel that option 2 is just helping people who haven't grasped how async works and aren't using inquirer properly anyway. Part of me thinks that it would be better for them if we throw an error as they will then understand that they need to use callbacks and can't just call them serially.

Item separator

It would be useful to be able to insert a separator between items to group them. Could just accept a string and let the user chose if it should be empty, --------, or something else.

Example:

inquirer-separator

It would eg be useful in yo where we display a long list of options, but some should be grouped together distinctively.

Add unicode for Windows

By limiting the unicode range in which to select unicode, we should be able to use supported unicode character by Consolas (default windows cmd font). This would allow having a closer style parity between Windows and Unix.

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.