Last active
October 23, 2018 00:33
-
-
Save joaofnds/9bc51b44100c10da378825751481b8bf to your computer and use it in GitHub Desktop.
Heroku-like spinner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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