-
-
Notifications
You must be signed in to change notification settings - Fork 281
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
Cannot create custom prompt that extends MultiSelect #428
Comments
Hi @eAlexandrohin, sorry for the late reply. For now, you can do this instead: const colors = require('ansi-colors');
const { MultiSelect } = require('enquirer');
class Choose extends MultiSelect {
constructor(options) {
super({ ...options });
}
indicator(state, choice) {
return ` ${choice.enabled ? '●' : '○'}`;
}
result(result) {
return Object.values(this.map(result));
}
format() {
if (!this.state.submitted || this.state.cancelled) return '';
if (Array.isArray(this.selected) && this.selected.length > 0) {
return `${colors.bold.greenBright('done!')}`;
}
return;
}
}
const chooseSomething = new Choose({
name: 'chosenSomething',
message: 'Choose something:',
limit: 2,
choices: ['foo', 'bar', 'baz'],
pointer: '>',
emptyError: `${colors.bold.redBright('none were selected.')}`,
footer: `\nUse ${colors.bold.cyanBright('↑/↓')} keys with ${colors.bold.cyanBright(
'Space[ ⎵ ]'
)} and ${colors.bold.cyanBright('Enter[ ↵ ]')}.`,
styles: {
default: colors.reset,
strong: colors.bold.cyanBright,
primary: colors.bold.greenBright,
em: colors.bold.greenBright,
success: colors.bold.greenBright
}
});
chooseSomething
.run()
.then(async(result) => {
// ...
})
.catch(console.error); I think that should work with chalk too, I already had ansi-colors installed so I just used that. |
Sorry for late reply too, @jonschlinkert :) So, there is no way, for now, to define all needed properties in class to make usage simple and compact like in my example? Guess, it is pointless to do that this way then. I will just continue sticking with creating new MultiSelect each time. Also, tried running your solution and the indicator doesnt work anymore. ¯\(ツ)/¯ Anyway, thank you for your time. <3 |
Trying to make prompt template via custom prompt:
And got this error:
The text was updated successfully, but these errors were encountered: