bombshell-dev / clack

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

[Request] Spinner to handle cleaning up on process exit #106

Closed privatenumber closed 11 months ago

privatenumber commented 1 year ago

Is your feature request related to a problem? Please describe.

When the logic between spinner.start() & spinner.stop() throws an error and terminates the process, it seems to cause issues with the terminal cursor:

https://github.com/Nutlope/aicommits/pull/154/

So to work around this, the logic block needs to be wrapped in a try-finally to call spinner.stop().

Describe the solution you'd like

An exit hook inside spinner to cleanup the readline prompt if the process is about to exit:

process.on('exit', () => {
    if (spinnerActive) {
        // terminate readline
    }
})

Describe alternatives you've considered Delegate try-finally wrappers to user-land, but it's not very ergonomic to do this every time spinner is used.

Additional context Add any other context or screenshots about the feature request here.

ulken commented 1 year ago

Sounds like a no-brainer to me. Care to open a PR?