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

Add support for logging progress messages #69

Open
weikanglim opened this issue Jul 20, 2022 · 0 comments
Open

Add support for logging progress messages #69

weikanglim opened this issue Jul 20, 2022 · 0 comments

Comments

@weikanglim
Copy link

It is sometimes desirable to log messages while rendering the spinner. Users can do this currently is by not setting a StopMessage and using Stop + Start to temporarily pause the spinner, remove the spinner text and log the message to standard output (example program below).

While this does work, I think it is worthwhile to add a spinner.LogMessage API that adds this functionality. Would love to contribute changes here if this idea makes sense.

package main

import (
	"fmt"
	"time"

	"github.com/theckman/yacspin"
)

func logProgress(spin *yacspin.Spinner, message string) {
	spin.Stop()
	fmt.Println(message)
	spin.Start()
}

func main() {
	spin, _ := yacspin.New(yacspin.Config{
		Frequency: time.Millisecond * 200,
		CharSet:   yacspin.CharSets[9],
		Message:   " Spinning...",
	})

	spin.Start()

	for i := 0; i < 10; i++ {
		logProgress(spin, fmt.Sprintf("Step %d completed.", i))
		time.Sleep(1000 * time.Millisecond)
	}

	spin.Stop()
}
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

1 participant