diff --git a/CLAUDE.md b/CLAUDE.md index a1033f3..acf3357 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -50,7 +50,7 @@ View (hiccup) → Render (ANSI string) → Terminal (raw mode I/O) 2. Runtime renders initial view 3. Input loop reads keys, puts messages on channel 4. Update function processes messages, may return commands -5. Commands execute async (ticks, batches), put results back on channel +5. Commands execute async (timers, batches), put results back on channel 6. Loop until `[:quit]` command ### Command Types diff --git a/README.md b/README.md index 25a6749..7cbeaa4 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,7 @@ Commands are returned from your `update` function to trigger side effects: | Command | Description | |---------|-------------| | `tui/quit` | Exit the application | -| `(tui/tick ms)` | Send `:tick` after ms milliseconds | +| `(tui/after ms msg)` | Send `msg` after ms milliseconds | | `(tui/batch c1 c2)` | Run commands in parallel | | `(tui/sequentially c1 c2)` | Run commands sequentially | | `(fn [] msg)` | Custom async function returning a message | diff --git a/docs/api-reference.md b/docs/api-reference.md index 33d3c03..09c413f 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -70,18 +70,19 @@ Constant value returned as a command to exit the application. [model nil])) ``` -### tick +### after ```clojure -(tick ms) +(after ms msg) ``` -Create a command that sends `:tick` message after a delay. +Create a command that sends `msg` after a delay. **Parameters:** - `ms` - Delay in milliseconds +- `msg` - Message to send after the delay -**Returns:** A tick command +**Returns:** An async command **Example:** @@ -89,14 +90,14 @@ Create a command that sends `:tick` message after a delay. ;; Start a 1-second timer (defn update-fn [model msg] (case msg - :tick [(update model :seconds inc) (tui/tick 1000)] + :timer-tick [(update model :seconds inc) (tui/after 1000 :timer-tick)] [model nil])) -;; Initial tick +;; Initial timer (tui/run {:init {:seconds 0} :update update-fn :view view - :init-cmd (tui/tick 1000)}) + :init-cmd (tui/after 1000 :timer-tick)}) ``` ### batch diff --git a/docs/examples.md b/docs/examples.md index e8d86e0..387748a 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -125,10 +125,10 @@ r: reset q: quit ## Timer -A countdown timer demonstrating async commands with `tick`. +A countdown timer demonstrating async commands with `after`. **Features:** -- Async tick command +- Async timer command - State machine (running/paused/done) - Conditional rendering - Pause/resume functionality @@ -153,21 +153,21 @@ A countdown timer demonstrating async commands with `tick`. [model nil] (let [paused (not (:paused model))] [(assoc model :paused paused) - (when-not paused (tui/tick 1000))])) + (when-not paused (tui/after 1000 :timer-tick))])) ;; Reset with 'r' (tui/key= msg "r") [{:seconds initial-seconds :paused false :done false} - (tui/tick 1000)] + (tui/after 1000 :timer-tick)] - ;; Handle tick - (= msg :tick) + ;; Handle timer tick + (= msg :timer-tick) (if (:paused model) [model nil] (let [new-seconds (dec (:seconds model))] (if (pos? new-seconds) [{:seconds new-seconds :paused false :done false} - (tui/tick 1000)] + (tui/after 1000 :timer-tick)] [{:seconds 0 :paused false :done true} nil]))) :else @@ -201,7 +201,7 @@ A countdown timer demonstrating async commands with `tick`. (tui/run {:init {:seconds initial-seconds :paused false :done false} :update update-fn :view view - :init-cmd (tui/tick 1000)})) + :init-cmd (tui/after 1000 :timer-tick)})) ``` ### Output @@ -242,10 +242,10 @@ space: pause/resume r: reset q: quit ### Key Concepts -1. **Tick command**: `(tui/tick 1000)` sends `:tick` after 1 second -2. **Initial command**: `:init-cmd` starts the first tick +1. **After command**: `(tui/after 1000 :timer-tick)` sends `:timer-tick` after 1 second +2. **Initial command**: `:init-cmd` starts the first timer 3. **State machine**: Track `paused` and `done` states -4. **Conditional ticks**: Only schedule next tick when not paused +4. **Pause control**: Only schedule next `after` when not paused --- @@ -373,11 +373,11 @@ j/k: move space: toggle enter: confirm q: quit ## Spinner -An animated loading spinner demonstrating fast tick-based animation. +An animated loading spinner demonstrating fast timer-based animation. **Features:** - Multiple spinner styles -- Fast animation (80ms ticks) +- Fast animation (80ms intervals) - Tab to cycle styles - State machine (loading/done) @@ -419,10 +419,10 @@ An animated loading spinner demonstrating fast tick-based animation. ;; Reset with 'r' (tui/key= msg "r") [{:style-idx (:style-idx model) :frame 0 :done false} - (tui/tick 80)] + (tui/after 80 :spinner-frame)] - ;; Handle tick - (= msg :tick) + ;; Handle spinner frame + (= msg :spinner-frame) (if (:done model) [model nil] (let [style-key (nth spinner-order (:style-idx model)) @@ -430,7 +430,7 @@ An animated loading spinner demonstrating fast tick-based animation. interval (get-in spinners [style-key :interval]) next-frame (mod (inc (:frame model)) (count frames))] [(assoc model :frame next-frame) - (tui/tick interval)])) + (tui/after interval :spinner-frame)])) :else [model nil])) @@ -458,7 +458,7 @@ An animated loading spinner demonstrating fast tick-based animation. (tui/run {:init {:style-idx 0 :frame 0 :done false} :update update-fn :view view - :init-cmd (tui/tick 80)})) + :init-cmd (tui/after 80 :spinner-frame)})) ``` ### Output @@ -498,10 +498,10 @@ tab: change style space: complete r: restart q: quit ### Key Concepts -1. **Fast ticks**: Use short intervals (80-100ms) for smooth animation +1. **Fast timers**: Use short intervals (80-100ms) for smooth animation 2. **Frame-based animation**: Cycle through an array of frames 3. **Multiple styles**: Store different spinner configurations -4. **Stop animation**: Stop scheduling ticks when done +4. **Stop animation**: Stop scheduling timers when done --- diff --git a/docs/getting-started.md b/docs/getting-started.md index 976076f..4b4930f 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -269,7 +269,7 @@ Commands are how your application performs side effects. | Command | Description | |---------|-------------| | `tui/quit` | Exit the application | -| `(tui/tick ms)` | Send `:tick` message after delay | +| `(tui/after ms msg)` | Send `msg` after delay | | `(tui/batch cmd1 cmd2 ...)` | Run commands in parallel | | `(tui/sequentially cmd1 cmd2 ...)` | Run commands in sequence | @@ -284,9 +284,9 @@ Commands are returned as the second element of the update function's return vect (tui/key= msg "q") [model tui/quit] - ;; Return tick command (async runtime only) + ;; Return after command (async runtime only) (tui/key= msg "s") - [{:started true} (tui/tick 1000)] + [{:started true} (tui/after 1000 :timer-tick)] ;; No command :else @@ -304,11 +304,11 @@ Commands are returned as the second element of the update function's return vect (tui/key= msg "q") [model tui/quit] - ;; Handle tick message - (= msg :tick) + ;; Handle timer tick message + (= msg :timer-tick) (let [new-count (dec (:count model))] (if (pos? new-count) - [{:count new-count} (tui/tick 1000)] + [{:count new-count} (tui/after 1000 :timer-tick)] [{:count 0 :done true} nil])) :else @@ -325,7 +325,7 @@ Commands are returned as the second element of the update function's return vect (tui/run {:init {:count 10 :done false} :update update-fn :view view - :init-cmd (tui/tick 1000)})) ;; Start first tick + :init-cmd (tui/after 1000 :timer-tick)})) ;; Start first timer ``` ## Configuration Options