spinner

Platform independent Go module to print spinners on Terminal/ cmd

MIT License

Stars
7

spinner

Platform independent Go module to print spinners on Terminal/ cmd

Overview / Features

  • Have 80+ spinners, Segregated into ASCII(id: 1-999) and Unicode(id >= 1000) spinners

  • Custom (user-defined) spinners

  • Support rich color rendering output for the spinners (in both 16bit colors and Hexcodes)

  • Colors compatible with Windows system.

  • Universal and Stable API method

  • Made with concurrency handling in mind

Documentation

Complete documentation of the API is hosted at pkg.go.dev

Spinners

Below Tables show spinners with their IDs. Use it as reference

ASCII Spinners (ID 1 to 999)

Unicode Spinners (ID >= 1000)

Working Examples

These are simple examples. For more Indepth uses refer the API documentation hosted at pkg.go.dev

New Spinner

The following code creates a new spinner and uses it

package main

import (
  "time"
  "log"

 spinner "github.com/Yash-Handa/spinner"
)

func main() {
  sp, err := spinner.New(4, 50 * time.Millisecond, spinner.Cyan, spinner.Normal)
  if err != nil {
    log.Fatal(err)
  }

  sp.SetPostText("  Loading Content")
  sp.SetDoneText("Hurray spinner worked\n")

  sp.Start()                       // the spinner starts
  time.Sleep(3 * time.Second)      // after 3 seconds
  sp.SetColor(spinner.Magenta, "") // use previous background color
  sp.SetInterval(100 * time.Millisecond)
  sp.SetPostText("  The color and speed Changed !!")
  time.Sleep(3 * time.Second)
  sp.Stop() // the spinner stops
}

Custom Spinner

The following code creates a custom spinner using user defined symbols.

package main

import (
  "time"
  "log"

  spinner "github.com/Yash-Handa/spinner"
)

func main() {
  symbols := []string{"N   ", "IN  ", "PIN ", "SPIN", " SPI", "  SP", "   S", "    "}
  sp, err := spinner.Custom(symbols, 0, spinner.Red, spinner.Normal)
  if err != nil {
    log.Fatal(err)
  }

  sp.SetPostText("  A custom spinner")

  sp.Start()                  // the spinner starts
  time.Sleep(3 * time.Second) // after 3 seconds the color changes to lime green
  sp.SetColor("00e600", spinner.HexBgNormal)
  // spinner.HexBgNormal is used with Hex foreground to indicate that no background color to be used
  sp.SetPostText("  The color Changed !!")
  time.Sleep(3 * time.Second)
  sp.Stop() // the spinner stops
}

Contributions

The Project is Open Sourced under MIT License and will always welcomes Pull Request. Please read CONTRIBUTING.md.