1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
package putils
import "github.com/pterm/pterm"
// RunWithSpinner starts a spinner, then runs a function and after the function is done, the spinner will stop again.
func RunWithSpinner(spinner *pterm.SpinnerPrinter, f func(spinner *pterm.SpinnerPrinter) error) error {
s, err := spinner.Start()
if err != nil {
return err
}
err = f(s)
if s.IsActive {
s.Stop()
}
return err
}
// RunWithDefaultSpinner starts a default spinner, then runs a function and after the function is done, the spinner will stop again.
func RunWithDefaultSpinner(initzialSpinnerText string, f func(spinner *pterm.SpinnerPrinter) error) error {
return RunWithSpinner(pterm.DefaultSpinner.WithText(initzialSpinnerText), f)
}
|