sboudrias / inquirer.js Goto Github PK
View Code? Open in Web Editor NEWA collection of common interactive command line user interfaces.
License: MIT License
A collection of common interactive command line user interfaces.
License: MIT License
User should be able to return error messages from a failed validation (related to #1)
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
First, thanks for the new library. After using it I have some suggestions to simplify the prompts and make them feel less lengthy.
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.
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
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?
Shouldn't default text to white - it should reset to default.
Request from Yeoman, getting the Grunt-init color scheme.
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
When going from one option to the other in the list prompt it sometimes flicker in OS X 10.8 Terminal.app.
Video: https://dl.dropboxusercontent.com/u/71884/inquirer-flicker-bug.m4v
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
0.3.0
presented a regression in the nested prompts support (events where duplicated). It really needs a better unit test so this don't happens again.
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?
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.
Asked over here: yeoman/generator#250 (comment)
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(); } }
If I ctrl+c the prompt the caret is forever hidden.
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:
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.
Checkout to pass directly the RL instead of a façade here https://github.com/SBoudrias/Inquirer.js/blob/master/lib/inquirer.js#L49-L61
Must hide user input.
Sometimes it would be useful to be able to select multiple options in a list. Currently the list
prompt is like a radio group. Could be useful with a checkbox group.
Need it for: https://github.com/sindresorhus/generator-pure/issues/2
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?
Right now there's no support for using line return inside questions or choices.
User should be able to validate the answer returned by the client.
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 ✖⃝
Complete detail here:
yeoman/generator#284
When an input prompt is followed by an input prompt it still inserts a blank line at the bottom of the terminal, but that's not a big deal. If you end up fixing this sometime in the future, great, but no worries if not.
If I'm not mistaken, confirm
currently does not accept allow false
as default. It would be nice to have this added.
It's distracting and it's possible to hide it: https://github.com/substack/node-charm#charmcursorvisible
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 :-)
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.
Right now, I think I'll only catch missing required parameters.
We'll see with time if we need to add some stuff up.
Related use case: yeoman/yo#57
Is there a way to use the expand-type list, but in an auto-expanded way? Thanks!
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);
});
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:
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, " ") );
});
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.
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!
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.
This may allow user to slugify a phrase or use some content filter like toLowerCase
.
When backspace is pressed, the current line is completly removed and we go back to a default >
prompt...
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.
It would be nice to override the default pageSize (7).
When using the confirm prompt and set default: false
it still shows the (Y/n)
hint, while it should be (y/N)
.
Test case: https://github.com/h5bp/generator-h5bp
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)
Migrated from #62 (separate issue that was brought up)
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).
Throw an error if inquirer.prompt
is called before a previous call has finished (removed event listeners and called callback).
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.
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:
It would eg be useful in yo
where we display a long list of options, but some should be grouped together distinctively.
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.
Would be useful to allow 1-9 to quickly select options in list
and checkbox
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.