// Color will set the struct field for the given color to be used func (s *Spinner) Color(c string) error { if validColor(c) { switch c { case "red": s.color = color.New(color.FgRed).SprintFunc() s.Restart() case "yellow": s.color = color.New(color.FgYellow).SprintFunc() s.Restart() case "green": s.color = color.New(color.FgGreen).SprintFunc() s.Restart() case "magenta": s.color = color.New(color.FgMagenta).SprintFunc() s.Restart() case "blue": s.color = color.New(color.FgBlue).SprintFunc() s.Restart() case "cyan": s.color = color.New(color.FgCyan).SprintFunc() s.Restart() case "white": s.color = color.New(color.FgWhite).SprintFunc() s.Restart() default: return errors.New("invalid color") } } return nil }
// New provides a pointer to an instance of Spinner with the supplied options func New(c []string, t time.Duration) *Spinner { s := &Spinner{ Delay: t, stopChan: make(chan bool, 1), color: color.New(color.FgWhite).SprintFunc(), w: color.Output, } s.UpdateCharSet(c) return s }
func (m *Manifest) prefixForEntry(name string, pos int) string { longest := 0 for name, _ := range *m { if len(name) > longest { longest = len(name) } } c := color.New(Colors[pos%len(Colors)]).SprintFunc() return c(name + strings.Repeat(" ", longest-len(name)) + " |") }