Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
todo: recipes #33
todo: recipes #33
Comments
|
I'd love to have a multi-select editable. This way I could select X tags from a list, and even add choices with some key ( |
|
Thank you for pointing me to the right issue. I must have looked better. It looks great! |
|
I'm interested in seeing examples for showing loading indicators upon (async) validation. Case in point: I've made a simple prompt that waits for the user to perform an action (in this case solving a merge conflict), and then submitting (pressing enter). If the merge conflicts were solved the prompt will end successfully, if not it'll require the user to try again. If an exception is thrown by the validation (eg. file access not available) the prompt should end and the exception be re-thrown. Is the following const { Prompt } = require("enquirer");
class EnterPrompt extends Prompt {
constructor({ customValidation, ...options }) {
super(options);
this.customValidation = customValidation;
this.cursorHide();
}
async validate() {
if (this.inProgressPromise) {
return this.inProgressPromise;
}
this.render();
this.inProgressPromise = this.customValidation();
const value = await this.inProgressPromise;
this.inProgressPromise = null;
return value;
}
async render() {
const { size } = this.state;
this.clear(size);
const prefix = await this.prefix();
const message = await this.message();
let promptLine;
// waiting for user to submit
if (!this.state.submitted) {
promptLine = `${prefix} ${message}\n\nPress enter to continue`;
// waiting for async validation
} else if (
!this.state.cancelled &&
this.state.submitted &&
this.state.validating
) {
promptLine = `${prefix} ${message}\n\nValidating...`;
// finished
} else if (this.state.submitted || this.state.cancelled) {
promptLine = `${prefix} ${message}`;
}
this.write(promptLine);
this.restore();
}
}
async function init() {
let i = 0;
await new EnterPrompt({
message: "Resolve conflicts",
async customValidation() {
i++;
return new Promise((resolve) => setTimeout(() => resolve(i > 2), 1000));
}
}).run();
console.log("all conflicts resolved!");
}
init().catch((e) => {console.log("Error", e)}); |
What other examples would you like to See?