diff --git a/spinner.go b/spinner.go index b009cf7..07ebf18 100644 --- a/spinner.go +++ b/spinner.go @@ -285,10 +285,11 @@ func (s *Spinner) Start() { case <-s.stopChan: return default: + s.mu.Lock() if !s.active { + s.mu.Unlock() return } - s.mu.Lock() s.erase() if s.PreUpdate != nil { @@ -303,9 +304,9 @@ func (s *Spinner) Start() { outColor = fmt.Sprintf("\r%s%s%s ", s.Prefix, s.color(s.chars[i]), s.Suffix) } } else { - outColor = fmt.Sprintf("%s%s%s ", s.Prefix, s.color(s.chars[i]), s.Suffix) + outColor = fmt.Sprintf("\r%s%s%s ", s.Prefix, s.color(s.chars[i]), s.Suffix) } - outPlain := fmt.Sprintf("%s%s%s ", s.Prefix, s.chars[i], s.Suffix) + outPlain := fmt.Sprintf("\r%s%s%s ", s.Prefix, s.chars[i], s.Suffix) fmt.Fprint(s.Writer, outColor) s.lastOutput = outPlain delay := s.Delay @@ -401,6 +402,7 @@ func (s *Spinner) erase() { for _, c := range []string{"\b", "\127", "\b", "\033[K"} { // "\033[K" for macOS Terminal fmt.Fprint(s.Writer, strings.Repeat(c, n)) } + fmt.Fprintf(s.Writer, "\r\033[K") // erases to end of line s.lastOutput = "" }