- Start/Stop
- Customizable character sets (spinners)
- Custom spinner color, background
- Custom spinner text
- Restarting and reversing the spinner
- Prefixed text, symbol and padding before the spinner
- Changing spinner settings while it is active
- Getting the spinner settings values
- Chain, pipe or redirect output
- Shows the seconds elasped since the spinner started (can be disabled)
- Ability to Stop and persist the spinner with custom text and a symbol
- Pre-built
Succeed
,Fail
andInfo
functions that stops and persists the spinner with pre-defined cross-platform symbol and text
import "github.com/AnishDe12020/spintron"
func main() {
s := spintron.New(spintron.Options{
Text: "Working...",
})
s.Start() // Starts the spinner with the initial text
// Some work that will take time. E.g. Downloading a file. Let us have a dummy
// function for now
err := DownloadFile()
if err != nil {
s.Fail("Failed to download the file") // Stops the spinner and shows a error sign with the given text
} else {
s.Success("Downloaded the file successfully") // Stops the spinner and shows a success sign with the given text
}
}
When a new spinner is created, it can be created with a struct of options. Here are the ones available -
The color of the spinner
The text after the spinner
Hide the cursor or not
A symbol that will come before the prefix text
Text that will come before the spinner
Character set used for the spinner
stdOut writer
Delay between frames in the character set
Number of chatacters in padding on the left of the spinner
Disable the elasped seconds timer
time.Sleep(time.Second * 2) // Simulate a long running process
s.Reverse() // Reverse the spinner's character set
s.Text = "I have been reversed"
time.Sleep(time.Second * 2) // Simulate a long running process
s.Stop() // Stops the spinner
time.Sleep(time.Second * 2) // Simulate a long running process
s.UpdateCharSet(spintron.CharSets["moon"]) // Update spinner to use a different character set
s.Text = "My character set has been updated"
time.Sleep(time.Second * 2) // Simulate a long running process
s.Stop() // Stops the spinner
time.Sleep(time.Second * 2) // Simulate a long running process
s.UpdateSpeed(time.Duration(50) * time.Millisecond) // Update spinner to use a different speed, here making it twice that of the default speed
s.Text = "My speed has been updated to make me faster"
time.Sleep(time.Second * 2) // Simulate a long running process
s.Stop() // Stops the spinner
time.Sleep(time.Second * 2) // Simulate a long running process
s.Padding = 10 // Add a padding of 10 characters to the left of the spinner
s.Text = "My padding has been updated"
time.Sleep(time.Second * 2) // Simulate a long running process
s.Stop() // Stops the spinner
time.Sleep(time.Second * 2) // Simulate a long running process
s.StopAndPersist("π", "Heya") // Stops the spinner and persists it with a custom symbol and text
s.Succeed("Done!") // Stops the spinner and persists it with a success sign and message
s.Fail("Uh oh! Something went wrong!") // Stops the spinner and persists it with an error sign and message
s.Info("Star the repo") // Stops the spinner and persists it with an info sign and message
All commits uptil 561dc95 are made by Brian Downs and the contributors to the original repository, briandowns/spinner. The project has since been renamed to Spintron to differentiate from the original project.
This is a fork of the original Go Spinner repository Brian Downs licensed under Apache 2.0.