bombshell-dev / clack

Effortlessly build beautiful command-line apps
https://clack.cc
5.53k stars 90 forks source link

[Question] Are spinner task groups no longer supported? #157

Closed zateutsch closed 1 year ago

zateutsch commented 1 year ago

Can't find this from the readme on the latest version of prompts.

image

Mist3rBru commented 1 year ago

@zateutsch It is going to be available on next release, for now you can use spinner individually

cpreston321 commented 1 year ago

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 🚀

zateutsch commented 1 year ago

@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?

Mist3rBru commented 1 year ago

@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)
})
zateutsch commented 1 year ago

Thanks for the answers. Closing as resolved.

mikenikles commented 1 year ago

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.