mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
43 lines
625 B
Go
43 lines
625 B
Go
package common
|
|
|
|
import (
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
// TODO: move me to a common module (used in multiple repos)
|
|
|
|
const (
|
|
SpinnerDotSet = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
|
|
)
|
|
|
|
type Spinner struct {
|
|
index int
|
|
charset []string
|
|
lock sync.Mutex
|
|
}
|
|
|
|
func NewSpinner(charset string) Spinner {
|
|
return Spinner{
|
|
charset: strings.Split(charset, ""),
|
|
}
|
|
}
|
|
|
|
func (s *Spinner) Current() string {
|
|
s.lock.Lock()
|
|
defer s.lock.Unlock()
|
|
|
|
return s.charset[s.index]
|
|
}
|
|
|
|
func (s *Spinner) Next() string {
|
|
s.lock.Lock()
|
|
defer s.lock.Unlock()
|
|
c := s.charset[s.index]
|
|
s.index++
|
|
if s.index >= len(s.charset) {
|
|
s.index = 0
|
|
}
|
|
return c
|
|
}
|