8000 cli/ui/spinner.go at cooper/templates · hmmhmmhm/cli · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 1.27 KB

spinner.go

File metadata and controls

49 lines (38 loc) · 1.27 KB
package ui
import (
"os"
"time"
"github.com/briandowns/spinner"
)
type TrainSpinner []string
var (
TrainRight TrainSpinner = []string{"🚅", "🚅🚋", "🚅🚋🚋", "🚅🚋🚋🚋", "🚅🚋🚋🚋🚋", "🚅🚋🚋🚋🚋🚋", "🚅🚋🚋🚋🚋🚋🚋", "🚅🚋🚋🚋🚋🚋🚋🚋", "🚅🚋🚋🚋🚋🚋🚋🚋🚋"}
TrainLeft TrainSpinner = []string{" 🚅", " 🚅🚋", " 🚅🚋🚋", " 🚅🚋🚋🚋", " 🚅🚋🚋🚋🚋", " 🚅🚋🚋🚋🚋🚋", " 🚅🚋🚋🚋🚋🚋🚋", " 🚅🚋🚋🚋🚋🚋🚋🚋", "🚅🚋🚋🚋🚋🚋🚋🚋🚋"}
TrainEmojis TrainSpinner = []string{"🚝", "🚅", "🚄", "🚇", "🚞", "🚈", "🚉", "🚂", "🚃", "🚊", "🚋"}
)
type SpinnerCfg struct {
Message string
Tokens []string
Duration time.Duration
}
var s = &spinner.Spinner{}
func StartSpinner(cfg *SpinnerCfg) {
if cfg.Tokens == nil {
cfg.Tokens = TrainRight
}
if cfg.Duration.Microseconds() == 0 {
cfg.Duration = time.Duration(100) * time.Millisecond
}
s = spinner.New(cfg.Tokens, cfg.Duration)
s.Writer = os.Stdout
if cfg.Message != "" {
s.Suffix = " " + cfg.Message
}
s.Start()
}
func StopSpinner(msg string) {
if msg != "" {
s.FinalMSG = msg + "\n"
}
s.Stop()
}
0