Start the SpinnerPrinter.
(text ...any)
| 146 | |
| 147 | // Start the SpinnerPrinter. |
| 148 | func (s SpinnerPrinter) Start(text ...any) (*SpinnerPrinter, error) { |
| 149 | s.IsActive = true |
| 150 | s.startedAt = time.Now() |
| 151 | activeSpinnerPrinters = append(activeSpinnerPrinters, &s) |
| 152 | |
| 153 | if len(text) != 0 { |
| 154 | s.Text = Sprint(text...) |
| 155 | } |
| 156 | |
| 157 | go func() { |
| 158 | for s.IsActive { |
| 159 | for _, seq := range s.Sequence { |
| 160 | if !s.IsActive { |
| 161 | continue |
| 162 | } |
| 163 | if RawOutput { |
| 164 | time.Sleep(s.Delay) |
| 165 | continue |
| 166 | } |
| 167 | |
| 168 | var timer string |
| 169 | if s.ShowTimer { |
| 170 | timer = " (" + time.Since(s.startedAt).Round(s.TimerRoundingFactor).String() + ")" |
| 171 | } |
| 172 | Fprinto(s.Writer, s.Style.Sprint(seq)+" "+s.MessageStyle.Sprint(s.Text)+s.TimerStyle.Sprint(timer)) |
| 173 | s.currentSequence = seq |
| 174 | time.Sleep(s.Delay) |
| 175 | } |
| 176 | } |
| 177 | }() |
| 178 | return &s, nil |
| 179 | } |
| 180 | |
| 181 | // Stop terminates the SpinnerPrinter immediately. |
| 182 | // The SpinnerPrinter will not resolve into anything. |