A Go library for creating and managing multiple spinners in parallel using goroutines.
- Create multiple spinners that can run concurrently
- Customize colors for success and failure states
- Adjust spinner frequency
- Thread-safe operations
- Simple and intuitive API
go get github.com/thompsonja/multispinnerpackage main
import (
"fmt"
"time"
"github.com/thompsonja/multispinner"
)
func main() {
// Create a new spinner with default configuration
spinner := multispinner.Create(multispinner.DefaultConfig())
// Register two spinners
index1 := spinner.Register()
index2 := spinner.Register()
// Start the spinners
spinner.Start(index1, "Processing task 1...")
spinner.Start(index2, "Processing task 2...")
// Simulate some work
time.Sleep(2 * time.Second)
// Update message for spinner 1
spinner.Message(index1, "Almost done with task 1...")
// Simulate more work
time.Sleep(1 * time.Second)
// Stop the spinners
spinner.Stop(index1, "Task 1 completed successfully!")
spinner.StopWithError(index2, fmt.Errorf("Task 2 failed: connection timeout"))
}Creates a new spinner instance with the given configuration.
spinner := multispinner.Create(multispinner.Config{
SuccessColor: "\033[32m", // Green
FailureColor: "\033[31m", // Red
Frequency: 100 * time.Millisecond,
})Registers a new spinner and returns its index.
index := spinner.Register()Updates the message for a specific spinner.
spinner.Message(index, "New message")Starts a spinner with the given message.
spinner.Start(index, "Starting task...")Stops a spinner with a success message.
spinner.Stop(index, "Task completed successfully!")Stops a spinner with an error message.
spinner.StopWithError(index, fmt.Errorf("Task failed: %v", err))