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

Spinner is not being removed from the terminal #391

Open
Wagnerbr90 opened this issue Aug 22, 2022 · 6 comments
Open

Spinner is not being removed from the terminal #391

Wagnerbr90 opened this issue Aug 22, 2022 · 6 comments

Comments

@Wagnerbr90
Copy link

I'm facing a problem using the pterm in our CLI, sometimes the spinner is not being removed from the terminal, as you can see below ("Getting plan...").

I've noticed that when we set "spinner.Success() or spinner.Fail()", it should clear the line in the terminal, but sometimes it doesn't work, apparently

unnamed

@MarvinJWendt
Copy link
Member

Hi, this is the docs repo 😉
I'll move the issue to the main repo.

@MarvinJWendt MarvinJWendt transferred this issue from pterm/docs Aug 22, 2022
@MarvinJWendt
Copy link
Member

Do you have any reproducible code example on that? I would tackle the issue, but I cannot reproduce it.

@Wagnerbr90
Copy link
Author

Wagnerbr90 commented Jan 6, 2023

We are just setting the spinner at start

spinner, _ = spn.GetDefaultSpinner(i18n.Translator.Translate("GettingApisAndPlanSpinner"), false)
// spn is from an import
// When things are done, we finish it...
spinner.Success()

As u can see above, most of the time it works, but sometimes it doesn't

@MarvinJWendt
Copy link
Member

MarvinJWendt commented Jan 6, 2023

Could you please also share the configuration of the spinner (spn.GetDefaultSpinner)?

@Wagnerbr90
Copy link
Author

Could you please also share the configuration of the spinner (spn.GetDefaultSpinner)?

func GetDefaultSpinner(message string, showFinalMessage bool) (*pterm.SpinnerPrinter, error) {
	spinner, err := pterm.DefaultSpinner.Start(message)
	if err != nil {
		return nil, err
	}

	spinner.SuccessPrinter = printer.NewPrefixPrinter("SUCCESS ", &pterm.ThemeDefault.SuccessMessageStyle)
	spinner.FailPrinter = printer.NewPrefixPrinter("ERROR   ", &pterm.ThemeDefault.ErrorMessageStyle)
	spinner.InfoPrinter = printer.NewPrefixPrinter("INFO    ", &pterm.ThemeDefault.DefaultText)
	spinner.WarningPrinter = printer.NewPrefixPrinter("WARNING ", &pterm.ThemeDefault.WarningMessageStyle)

	spinner.RemoveWhenDone = !showFinalMessage

	return spinner, nil
}

@MarvinJWendt
Copy link
Member

I played around a little and I could replicate this issue very rarely.
This is related to a concurrency issue in the spinner, discovered in #423.

At the current time, it doesn't seem like an easy fix, as we would have to introduce a better concurrency pattern for all of our live printers (which might be overdue, looking at the current one).

I made a new issue with a proposal to change our concurrency pattern for all live printers in #439.

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