Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions output/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ package output

import (
"fmt"
"sync"
"time"

"github.com/gosuri/uilive"
)

var spinnerCharset = []rune{'⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'}
var mu = sync.Mutex{}

type Spinner struct {
prefix string
Expand All @@ -46,7 +48,10 @@ func (s *Spinner) Start() {
}

func (s *Spinner) run() {
mu.Lock()
// writes to global variable, need a global lock to avoid race conditions
writer := uilive.New()
mu.Unlock()

ticker := time.NewTicker(100 * time.Millisecond)

Expand All @@ -56,7 +61,10 @@ func (s *Spinner) run() {
select {
case <-s.done:
_, _ = fmt.Fprintf(writer, "\r")
mu.Lock()
// writes to global variable, need a global lock to avoid race conditions
_ = writer.Flush()
mu.Unlock()
close(s.done)
return
case <-ticker.C:
Expand Down
Loading