mirror of
https://github.com/safedep/vet.git
synced 2025-12-10 13:43:01 -06:00
40 lines
560 B
Go
40 lines
560 B
Go
package ui
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
var spinnerChan chan bool
|
|
|
|
func StartSpinner(msg string) {
|
|
style := `⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏`
|
|
frames := []rune(style)
|
|
length := len(frames)
|
|
|
|
spinnerChan = make(chan bool)
|
|
|
|
ticker := time.NewTicker(100 * time.Millisecond)
|
|
go func() {
|
|
pos := 0
|
|
|
|
for {
|
|
select {
|
|
case <-spinnerChan:
|
|
ticker.Stop()
|
|
return
|
|
case <-ticker.C:
|
|
fmt.Printf("\r%s ... %s", msg, string(frames[pos%length]))
|
|
pos += 1
|
|
}
|
|
}
|
|
}()
|
|
}
|
|
|
|
func StopSpinner() {
|
|
spinnerChan <- true
|
|
|
|
fmt.Printf("\r")
|
|
fmt.Println()
|
|
}
|