Skip to content

Add support for logging progress messages  #69

@weikanglim

Description

@weikanglim

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()
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions