Closed zateutsch closed 1 year ago
@zateutsch It is going to be available on next release, for now you can use spinner
individually
Hello @zateutsch 👋🏼
This is currently staged for release https://github.com/natemoo-re/clack/pull/149. This feature is somewhat new and is tied #152 but doesn't solve the issue completely. So I am waiting on a response from him. I also wanted to crunch some other bugs before the next release.
Thanks, CP 🚀
@cpreston321 @Mist3rBru Thanks for the speedy answer.
As a follow up, is there any way to listen for a cancel during a spinner as it is currently implemented?
@zateutsch the spinner
has a built in hook that handle this, but if you want to, you can try something like this:
const s = p.spinner()
s.start('First message')
// do stuff...
process.on('exit', () => {
// handle cancel...
s.stop('Last message')
process.exit(0)
})
Thanks for the answers. Closing as resolved.
FWIW, I learned this leads to a Node.js memory leak warning once you stop 11 spinners (yes, I have a rather complex CLI 😅).
I ended up with the following helpers to avoid the warning:
function exitProcess() {
process.stdout.write("\n");
process.exit(1);
}
/**
* @see https://github.com/natemoo-re/clack/issues/134#issuecomment-1694564106
*/
export function stopSpinner(s: ReturnType<typeof spinner>, message: string) {
s.stop(message);
process.removeListener("SIGINT", exitProcess);
process.on("SIGINT", exitProcess);
}
Update: Just as I posted that, I realized we could just use process.once('exit', ...)
and avoid all the helpers I posted above. I haven't tested, but if I understand once
correctly, it achieves the same as the helpers above.
Can't find this from the readme on the latest version of prompts.