Commit 4a2f5d44 authored by Alexandre Viau's avatar Alexandre Viau

New upstream version 1.1.0

parents
# go-spin
Little terminal spinner lib.
View the [docs](http://godoc.org/github.com/tj/go-spin).
## Installation
```
$ go get github.com/tj/go-spin
```
## Example
```go
s := spin.New()
for i := 0; i < 30; i++ {
fmt.Printf("\r \033[36mcomputing\033[m %s ", s.Next())
time.Sleep(100 * time.Millisecond)
}
```
## GIF FTW
![](./go-spin.gif)
# License
MIT
\ No newline at end of file
package main
import (
"fmt"
"time"
"github.com/tj/go-spin"
)
func main() {
s := spin.New()
show(s, "Default", spin.Default)
show(s, "Box1", spin.Box1)
show(s, "Box2", spin.Box2)
show(s, "Box3", spin.Box3)
show(s, "Box4", spin.Box4)
show(s, "Box5", spin.Box5)
show(s, "Box6", spin.Box6)
show(s, "Box7", spin.Box7)
show(s, "Spin1", spin.Spin1)
show(s, "Spin2", spin.Spin2)
show(s, "Spin3", spin.Spin3)
show(s, "Spin4", spin.Spin4)
show(s, "Spin5", spin.Spin5)
show(s, "Spin6", spin.Spin6)
show(s, "Spin7", spin.Spin7)
show(s, "Spin8", spin.Spin8)
show(s, "Spin9", spin.Spin9)
}
func show(s *spin.Spinner, name, frames string) {
s.Set(frames)
fmt.Printf("\n\n %s: %s\n\n", name, frames)
for i := 0; i < 30; i++ {
fmt.Printf("\r \033[36mcomputing\033[m %s ", s.Next())
time.Sleep(100 * time.Millisecond)
}
}
package spin
import "sync"
// Spinner types.
var (
Box1 = `⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏`
Box2 = `⠋⠙⠚⠞⠖⠦⠴⠲⠳⠓`
Box3 = `⠄⠆⠇⠋⠙⠸⠰⠠⠰⠸⠙⠋⠇⠆`
Box4 = `⠋⠙⠚⠒⠂⠂⠒⠲⠴⠦⠖⠒⠐⠐⠒⠓⠋`
Box5 = `⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠴⠲⠒⠂⠂⠒⠚⠙⠉⠁`
Box6 = `⠈⠉⠋⠓⠒⠐⠐⠒⠖⠦⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈`
Box7 = `⠁⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈⠈`
Spin1 = `|/-\`
Spin2 = `◴◷◶◵`
Spin3 = `◰◳◲◱`
Spin4 = `◐◓◑◒`
Spin5 = `▉▊▋▌▍▎▏▎▍▌▋▊▉`
Spin6 = `▌▄▐▀`
Spin7 = `╫╪`
Spin8 = `■□▪▫`
Spin9 = `←↑→↓`
Default = Box1
)
// Spinner is exactly what you think it is.
type Spinner struct {
mu sync.Mutex
frames []rune
length int
pos int
}
// New returns a spinner initialized with Default frames.
func New() *Spinner {
s := &Spinner{}
s.Set(Default)
return s
}
// Set frames to the given string which must not use spaces.
func (s *Spinner) Set(frames string) {
s.mu.Lock()
defer s.mu.Unlock()
s.frames = []rune(frames)
s.length = len(s.frames)
}
// Current returns the current rune in the sequence.
func (s *Spinner) Current() string {
s.mu.Lock()
defer s.mu.Unlock()
r := s.frames[s.pos%s.length]
return string(r)
}
// Next returns the next rune in the sequence.
func (s *Spinner) Next() string {
s.mu.Lock()
defer s.mu.Unlock()
r := s.frames[s.pos%s.length]
s.pos++
return string(r)
}
// Reset the spinner to its initial frame.
func (s *Spinner) Reset() {
s.mu.Lock()
defer s.mu.Unlock()
s.pos = 0
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment