MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / animateLoading

Method animateLoading

internal/ui/components/header.go:210–246  ·  view source on GitHub ↗

animateLoading displays an animated loading indicator.

(ctx context.Context)

Source from the content-addressed store, hash-verified

208
209// animateLoading displays an animated loading indicator.
210func (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}

Callers 1

ShowLoadingMethod · 0.95

Calls 4

SetTextMethod · 0.95
ReplaceSemanticTagsFunction · 0.92
QueueUpdateDrawMethod · 0.80
StopMethod · 0.45

Tested by

no test coverage detected