animateLoading displays an animated loading indicator.
(ctx context.Context)
| 208 | |
| 209 | // animateLoading displays an animated loading indicator. |
| 210 | func (h *Header) animateLoading(ctx context.Context) { |
| 211 | spinner := []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"} |
| 212 | index := 0 |
| 213 | ticker := time.NewTicker(100 * time.Millisecond) |
| 214 | defer ticker.Stop() |
| 215 | |
| 216 | for { |
| 217 | select { |
| 218 | case <-ctx.Done(): |
| 219 | return |
| 220 | case <-ticker.C: |
| 221 | h.mu.Lock() |
| 222 | loading := h.isLoading |
| 223 | h.mu.Unlock() |
| 224 | |
| 225 | if !loading { |
| 226 | return |
| 227 | } |
| 228 | |
| 229 | if h.app != nil { |
| 230 | spinnerChar := spinner[index] |
| 231 | h.app.QueueUpdateDraw(func() { |
| 232 | h.mu.Lock() |
| 233 | if !h.isLoading { |
| 234 | h.mu.Unlock() |
| 235 | return |
| 236 | } |
| 237 | currentMessage := h.loadingText |
| 238 | h.mu.Unlock() |
| 239 | h.SetText(theme.ReplaceSemanticTags(fmt.Sprintf("[info]%s %s[-]", spinnerChar, currentMessage))) |
| 240 | }) |
| 241 | } |
| 242 | |
| 243 | index = (index + 1) % len(spinner) |
| 244 | } |
| 245 | } |
| 246 | } |
no test coverage detected