Liking cljdoc? Tell your friends :D

Spinner

Animated loading indicators with 15 built-in animation styles.

Quick Example

(require '[charm.components.spinner :as spinner])

(def my-spinner (spinner/spinner :dots))

;; Initialize to start animation
(let [[s cmd] (spinner/spinner-init my-spinner)]
  ;; s is ready, cmd starts the tick loop
  )

;; In update function
(let [[s cmd] (spinner/spinner-update s msg)]
  ;; Handle spinner tick messages
  )

;; In view function
(spinner/spinner-view s)  ; => "⠋" (animates)

Creation Options

(spinner/spinner type & options)
OptionTypeDefaultDescription
typekeyword/map:dotsSpinner type or custom {:frames [...] :interval ms}
:stylestylenilStyle to apply to spinner frames
:idanyrandomUnique identifier for tick messages

Spinner Types

TypeFramesIntervalPreview
:line\| / - \100msClassic line spinner
:dotsBraille dots80msSmooth dot animation
:dotBraille patterns100msRotating dot
:jumpBraille jump100msJumping dot
:pulse█ ▓ ▒ ░125msPulsing block
:points∙∙∙ ●∙∙ ∙●∙ ∙∙●140msMoving point
:globe🌍 🌎 🌏250msRotating globe
:moonMoon phases125msMoon cycle
:monkey🙈 🙉 🙊300msThree monkeys
:meter▱▱▱ to ▰▰▰140msLoading meter
:hamburger☱ ☲ ☴300msTrigram animation
:ellipsis. .. ...300msGrowing dots
:arrows← ↖ ↑ ↗ → ↘ ↓ ↙100msRotating arrow
:bouncing-bar[= ]100msBouncing bar
:clockClock faces100msClock animation

Custom Spinner

(spinner/spinner {:frames ["◐" "◓" "◑" "◒"]
                  :interval 150})

Functions

spinner-init

(spinner/spinner-init s) ; => [spinner cmd]

Initialize the spinner and start the tick loop. Returns [spinner cmd] where cmd triggers the first tick.

spinner-update

(spinner/spinner-update s msg) ; => [spinner cmd]

Handle tick messages. Returns [spinner cmd] to continue animation, or [spinner nil] if message not handled.

spinner-view

(spinner/spinner-view s) ; => "⠋"

Render current frame as a string.

spinning?

(spinner/spinning? s msg) ; => boolean

Check if a message is a tick for this spinner.

Full Example

(ns my-app
  (:require
   [charm.components.spinner :as spinner]
   [charm.message :as msg]
   [charm.program :as program]))

(defn init []
  (let [[s cmd] (spinner/spinner-init (spinner/spinner :dots))]
    [{:spinner s
      :loading true}
     cmd]))

(defn update-fn [state msg]
  (cond
    (msg/key-match? msg "q")
    [state program/quit-cmd]

    :else
    (let [[s cmd] (spinner/spinner-update (:spinner state) msg)]
      [(assoc state :spinner s) cmd])))

(defn view [state]
  (str (spinner/spinner-view (:spinner state))
       " Loading data..."))

(program/run {:init init
              :update update-fn
              :view view})

Styled Spinner

(spinner/spinner :dots
                 :style (style/style :fg style/cyan :bold true))

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close