-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enquirer multi-step prompts #34
Comments
I will have a look. It should be related to the problems with the types. Default types of enquirer was not working correctly for me so i kind of rewrite the parts i required which are not correct at all. |
It seems I can make this work somehow with making both of the ctx.input = await task.prompt<boolean>([ 'Select', 'Select' ], [ { message: 'Do you love me?', choices: [ 'test', 'test', 'test', 'test' ] }, { message: 'Do you love me?', choices: [ 'test', 'test', 'test', 'test' ] } ]) The thing that this way will not be reliable enough for type-checking at least out of my league to implement. But you can achieve the same thing as follows if you even want an array as an end result as does the original ctx.input.push(await task.prompt('input', {
type: 'input',
name: 'name',
message: 'What is your name?'
})
ctx.input.push(await task.prompt('input', {
type: 'input',
name: 'username',
message: 'What is your username?'
}) If this is sufficient enough, please close out the issue. Elsewise it may need more brainstorming or changing it at the core. In the meantime I will try to remember why |
Thanks for the super-quick response! The above solution does indeed work for simple multi-step flows, but not for more advanced cases. For example, if using Is there any particular reason that enquirer interface was changed? It would be very nice it we could use enquirer directly, without a gateway in this package. |
Since |
🎉 This issue has been resolved in version 2.1.0-beta.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Please check out the beta channel, installable by listr2@beta, this required some internal changes and due to it the way of requesting input from the user has changed a little. Enquirer is now an optional dependency as well because I wanted to do that for quite some time. You should also explicitly install Enquirer to make this work. I am looking forward to your feedback. |
Hey! Just tested the beta channel. Enquirer arrays now work, which is very nice. However, there's some functionality that we have lost. Given this prompt definition, the [{
type: "select",
name: "firstInput",
message: "Please select something",
choices: ["A", "B", "C"],
},
{
type: "input",
name: "secondInput",
message: "Please type something in:",
skip: function (answers) {
return answers.firstInput === "A";
}
}] Additionally, if |
Validate seems to work for me like the one below. But skip does not pass in the results before it for me as well. But enquirer does not pass in the variable for skip I am not sure to have to check enquirer first. task: async (ctx, task): Promise<Record<string, boolean>> => ctx.input = await task.prompt<{ test: boolean, other: boolean }>([
{
type: 'Select',
name: 'first',
message: 'Please select something',
choices: [ 'A', 'B', 'C' ],
validate: (response): boolean | string => {
// i do declare you valid!
if (response === 'A') {
return true
}
}
},
{
type: 'Input',
name: 'second',
message: 'Please type something in:',
skip: (answers: { first: string }): boolean => {
console.log(answers)
return answers.first === 'A'
}
}
]) This seems the same with the enquirer as well. await Enquirer.prompt([
{
type: 'select',
name: 'first',
message: 'Please select something',
choices: [ 'A', 'B', 'C' ],
validate: (response): boolean | string => {
// i do declare you valid!
if (response === 'A') {
return true
}
}
},
{
type: 'input',
name: 'second',
message: 'Please type something in:',
skip: (answers: { first: string }): boolean => {
console.log(answers)
return answers.first === 'A'
}
}
]) |
This might be a problem with enquirer itself. I think you can get along with it separating multiple prompts to multiple listr tasks. It might not be the perfect code below but something along those lines. task = new Listr<Ctx>([
{
title: 'This task will get your input.',
task: async (ctx, task): Promise<Record<string, boolean>> => ctx.input = await task.prompt<{ test: boolean, other: boolean }>({
type: 'Select',
name: 'first',
message: 'Please select something',
choices: [ 'A', 'B', 'C' ],
validate: (response): boolean | string => {
// i do declare you valid!
if (response === 'A') {
return true
}
}
})
},
{
title: 'Now I will show the input value.',
skip: () => ctx.input === false
task: async (ctx, task): void => ctx.input = await task.prompt<{ test: boolean, other: boolean }>({
type: 'Select',
name: 'first',
message: 'Please select something',
choices: [ 'A', 'B', 'C' ],
validate: (response): boolean | string => {
// i do declare you valid!
if (response === 'A') {
return true
}
}
}),
options: {
persistentOutput: true
}
}
], { concurrent: false }) |
Hey, Yeah, currently I've separated the prompt tasks in individual listr steps. It's not ideal.. but works for now. Judging from Enquirer type definitions, the |
I might open a pull request to enquirer in upcoming days. I will close this issue again for now. |
# [2.1.0](v2.0.4...v2.1.0) (2020-06-03) ### Bug Fixes * **deps:** remove trivial deps ([de8dec0](de8dec0)) * **deps:** remove unnecassary types ([b37f416](b37f416)) * **deps:** updated deps to latest ([c4ad38f](c4ad38f)) * **figures:** made microsoft icons to use the fancy ones, even though it may fail in some cases ([f0e5817](f0e5817)), closes [#31](#31) * **prompt:** enquirer to peer ([cae55e9](cae55e9)) * **prompt:** types ([110130a](110130a)) * **prompts:** fixed type for array prompts, added name as mandatory ([a08b1e4](a08b1e4)) * **stream:** fixed streams added example ([614d89f](614d89f)), closes [#37](#37) ### Features * **prompt:** make prompt module optional, be more compatible to underlying enqurier ([64cecc1](64cecc1)), closes [#34](#34) * **prompt:** use enquirer directly ([b34e9d0](b34e9d0)), closes [#34](#34) * **renderer:** added hook and stdout support ([bd73c68](bd73c68)), closes [#31](#31)
🎉 This issue has been resolved in version 2.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Awesome work on bringing old listr back to life!
One small nuance that is pretty annoying though: currently listr2 does not have support for multi-step enquirer prompts. It would be amazing, if this feature could be added.
The text was updated successfully, but these errors were encountered: