mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 08:23:15 +01:00
* split UI from event handling Signed-off-by: Alex Goodman <wagoodman@gmail.com> * add event loop tests Signed-off-by: Alex Goodman <wagoodman@gmail.com> * use stereoscope cleanup function during signal handling Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * correct error wrapping in packages cmd Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * migrate ui event handlers to ui package Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * clarify command worker input var + remove dead comments Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
43 lines
629 B
Go
43 lines
629 B
Go
package components
|
|
|
|
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
|
|
}
|