Skip to content

Instantly share code, notes, and snippets.

@joaofnds
Last active October 23, 2018 00:33
Show Gist options
  • Select an option

  • Save joaofnds/9bc51b44100c10da378825751481b8bf to your computer and use it in GitHub Desktop.

Select an option

Save joaofnds/9bc51b44100c10da378825751481b8bf to your computer and use it in GitHub Desktop.
Heroku-like spinner
package main
import (
"fmt"
"time"
)
type spinner struct {
chars []string
current int
}
func (s *spinner) next() string {
s.current = (s.current + 1) % len(s.chars)
return s.chars[s.current]
}
func newSpinner() spinner {
return spinner{
chars: []string{"⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"},
current: 0,
}
}
func main() {
s := newSpinner()
fmt.Print("this gonna take a while... ")
for {
fmt.Printf("\b%s", s.next())
time.Sleep(100 * time.Millisecond)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment