simplify. remove tick

This commit is contained in:
2026-01-22 22:22:19 -05:00
parent 8cb4c82daa
commit 8c7cb24171
9 changed files with 133 additions and 88 deletions
+5 -5
View File
@@ -32,10 +32,10 @@
(tui/key= msg [:ctrl \c]))
[model tui/quit]
;; Tick - advance frame
(= (first msg) :tick)
;; Spinner frame - advance animation
(= msg :spinner-frame)
(if (:loading model)
[(update model :frame inc) (tui/tick 80)]
[(update model :frame inc) (tui/after 80 :spinner-frame)]
[model nil])
;; Space - simulate completion
@@ -53,7 +53,7 @@
;; r - restart
(tui/key= msg "r")
[(assoc model :loading true :frame 0 :message "Loading...")
(tui/tick 80)]
(tui/after 80 :spinner-frame)]
:else
[model nil]))
@@ -86,5 +86,5 @@
(tui/run {:init initial-model
:update update-model
:view view
:init-cmd (tui/tick 80)})
:init-cmd (tui/after 80 :spinner-frame)})
(println "Spinner demo finished."))
+6 -6
View File
@@ -17,27 +17,27 @@
(tui/key= msg [:ctrl \c]))
[model tui/quit]
;; Tick - decrement timer
(= (first msg) :tick)
;; Timer tick - decrement timer
(= msg :timer-tick)
(if (:running model)
(let [new-seconds (dec (:seconds model))]
(if (<= new-seconds 0)
;; Timer done
[(assoc model :seconds 0 :done true :running false) nil]
;; Continue countdown
[(assoc model :seconds new-seconds) (tui/tick 1000)]))
[(assoc model :seconds new-seconds) (tui/after 1000 :timer-tick)]))
[model nil])
;; Space - pause/resume
(tui/key= msg " ")
(let [new-running (not (:running model))]
[(assoc model :running new-running)
(when new-running (tui/tick 1000))])
(when new-running (tui/after 1000 :timer-tick))])
;; r - reset
(tui/key= msg "r")
[(assoc model :seconds 10 :done false :running true)
(tui/tick 1000)]
(tui/after 1000 :timer-tick)]
:else
[model nil]))
@@ -76,6 +76,6 @@
(let [final-model (tui/run {:init initial-model
:update update-model
:view view
:init-cmd (tui/tick 1000)})]
:init-cmd (tui/after 1000 :timer-tick)})]
(when (:done final-model)
(println "Timer completed!"))))