Skip to content
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

Can a spinner output line be erased/reused when promise is resolved? #232

Closed
mblais opened this issue Nov 13, 2023 · 2 comments
Closed

Can a spinner output line be erased/reused when promise is resolved? #232

mblais opened this issue Nov 13, 2023 · 2 comments

Comments

@mblais
Copy link

mblais commented Nov 13, 2023

I have a series of fetches where I display a spinner for each one, and when each fetch resolves, the spinner shows a checkmark and EOL. This results in a series of "checkmark" lines in my output (I'm not supplying any spinner text).

For these calls I would prefer to "re-use" the spinner line instead of having it output a newline when it's finished.

Is this possible?

@mblais mblais changed the title Can the spinner be erased when promise is resolved? Can a spinner output line be erased/reused when promise is resolved? Nov 13, 2023
@sindresorhus
Copy link
Owner

Just create a Ora instance and update the .spinner property manually as the promises resolve.

@mblais
Copy link
Author

mblais commented Dec 4, 2023

This works for me:

if (options.quiet) {
    // No spinner
    response    = await fetch(url, payload)
} else {
    // Show spinner
    const spinner = ora(options.verbose ? `${method} ${url}` : '').start()
    response      = await fetch(url, payload)
    if (options.verbose) spinner.succeed()           // Stop the spinner but keep the message line
    else                 spinner.stop()              // Delete the entire spinner line
} 

@mblais mblais closed this as completed Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants