update docs
This commit is contained in:
@@ -50,7 +50,7 @@ View (hiccup) → Render (ANSI string) → Terminal (raw mode I/O)
|
|||||||
2. Runtime renders initial view
|
2. Runtime renders initial view
|
||||||
3. Input loop reads keys, puts messages on channel
|
3. Input loop reads keys, puts messages on channel
|
||||||
4. Update function processes messages, may return commands
|
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
|
6. Loop until `[:quit]` command
|
||||||
|
|
||||||
### Command Types
|
### Command Types
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ Commands are returned from your `update` function to trigger side effects:
|
|||||||
| Command | Description |
|
| Command | Description |
|
||||||
|---------|-------------|
|
|---------|-------------|
|
||||||
| `tui/quit` | Exit the application |
|
| `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/batch c1 c2)` | Run commands in parallel |
|
||||||
| `(tui/sequentially c1 c2)` | Run commands sequentially |
|
| `(tui/sequentially c1 c2)` | Run commands sequentially |
|
||||||
| `(fn [] msg)` | Custom async function returning a message |
|
| `(fn [] msg)` | Custom async function returning a message |
|
||||||
|
|||||||
@@ -70,18 +70,19 @@ Constant value returned as a command to exit the application.
|
|||||||
[model nil]))
|
[model nil]))
|
||||||
```
|
```
|
||||||
|
|
||||||
### tick
|
### after
|
||||||
|
|
||||||
```clojure
|
```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:**
|
**Parameters:**
|
||||||
- `ms` - Delay in milliseconds
|
- `ms` - Delay in milliseconds
|
||||||
|
- `msg` - Message to send after the delay
|
||||||
|
|
||||||
**Returns:** A tick command
|
**Returns:** An async command
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
@@ -89,14 +90,14 @@ Create a command that sends `:tick` message after a delay.
|
|||||||
;; Start a 1-second timer
|
;; Start a 1-second timer
|
||||||
(defn update-fn [model msg]
|
(defn update-fn [model msg]
|
||||||
(case msg
|
(case msg
|
||||||
:tick [(update model :seconds inc) (tui/tick 1000)]
|
:timer-tick [(update model :seconds inc) (tui/after 1000 :timer-tick)]
|
||||||
[model nil]))
|
[model nil]))
|
||||||
|
|
||||||
;; Initial tick
|
;; Initial timer
|
||||||
(tui/run {:init {:seconds 0}
|
(tui/run {:init {:seconds 0}
|
||||||
:update update-fn
|
:update update-fn
|
||||||
:view view
|
:view view
|
||||||
:init-cmd (tui/tick 1000)})
|
:init-cmd (tui/after 1000 :timer-tick)})
|
||||||
```
|
```
|
||||||
|
|
||||||
### batch
|
### batch
|
||||||
|
|||||||
+20
-20
@@ -125,10 +125,10 @@ r: reset q: quit
|
|||||||
|
|
||||||
## Timer
|
## Timer
|
||||||
|
|
||||||
A countdown timer demonstrating async commands with `tick`.
|
A countdown timer demonstrating async commands with `after`.
|
||||||
|
|
||||||
**Features:**
|
**Features:**
|
||||||
- Async tick command
|
- Async timer command
|
||||||
- State machine (running/paused/done)
|
- State machine (running/paused/done)
|
||||||
- Conditional rendering
|
- Conditional rendering
|
||||||
- Pause/resume functionality
|
- Pause/resume functionality
|
||||||
@@ -153,21 +153,21 @@ A countdown timer demonstrating async commands with `tick`.
|
|||||||
[model nil]
|
[model nil]
|
||||||
(let [paused (not (:paused model))]
|
(let [paused (not (:paused model))]
|
||||||
[(assoc model :paused paused)
|
[(assoc model :paused paused)
|
||||||
(when-not paused (tui/tick 1000))]))
|
(when-not paused (tui/after 1000 :timer-tick))]))
|
||||||
|
|
||||||
;; Reset with 'r'
|
;; Reset with 'r'
|
||||||
(tui/key= msg "r")
|
(tui/key= msg "r")
|
||||||
[{:seconds initial-seconds :paused false :done false}
|
[{:seconds initial-seconds :paused false :done false}
|
||||||
(tui/tick 1000)]
|
(tui/after 1000 :timer-tick)]
|
||||||
|
|
||||||
;; Handle tick
|
;; Handle timer tick
|
||||||
(= msg :tick)
|
(= msg :timer-tick)
|
||||||
(if (:paused model)
|
(if (:paused model)
|
||||||
[model nil]
|
[model nil]
|
||||||
(let [new-seconds (dec (:seconds model))]
|
(let [new-seconds (dec (:seconds model))]
|
||||||
(if (pos? new-seconds)
|
(if (pos? new-seconds)
|
||||||
[{:seconds new-seconds :paused false :done false}
|
[{:seconds new-seconds :paused false :done false}
|
||||||
(tui/tick 1000)]
|
(tui/after 1000 :timer-tick)]
|
||||||
[{:seconds 0 :paused false :done true} nil])))
|
[{:seconds 0 :paused false :done true} nil])))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
@@ -201,7 +201,7 @@ A countdown timer demonstrating async commands with `tick`.
|
|||||||
(tui/run {:init {:seconds initial-seconds :paused false :done false}
|
(tui/run {:init {:seconds initial-seconds :paused false :done false}
|
||||||
:update update-fn
|
:update update-fn
|
||||||
:view view
|
:view view
|
||||||
:init-cmd (tui/tick 1000)}))
|
:init-cmd (tui/after 1000 :timer-tick)}))
|
||||||
```
|
```
|
||||||
|
|
||||||
### Output
|
### Output
|
||||||
@@ -242,10 +242,10 @@ space: pause/resume r: reset q: quit
|
|||||||
|
|
||||||
### Key Concepts
|
### Key Concepts
|
||||||
|
|
||||||
1. **Tick command**: `(tui/tick 1000)` sends `:tick` after 1 second
|
1. **After command**: `(tui/after 1000 :timer-tick)` sends `:timer-tick` after 1 second
|
||||||
2. **Initial command**: `:init-cmd` starts the first tick
|
2. **Initial command**: `:init-cmd` starts the first timer
|
||||||
3. **State machine**: Track `paused` and `done` states
|
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
|
## Spinner
|
||||||
|
|
||||||
An animated loading spinner demonstrating fast tick-based animation.
|
An animated loading spinner demonstrating fast timer-based animation.
|
||||||
|
|
||||||
**Features:**
|
**Features:**
|
||||||
- Multiple spinner styles
|
- Multiple spinner styles
|
||||||
- Fast animation (80ms ticks)
|
- Fast animation (80ms intervals)
|
||||||
- Tab to cycle styles
|
- Tab to cycle styles
|
||||||
- State machine (loading/done)
|
- State machine (loading/done)
|
||||||
|
|
||||||
@@ -419,10 +419,10 @@ An animated loading spinner demonstrating fast tick-based animation.
|
|||||||
;; Reset with 'r'
|
;; Reset with 'r'
|
||||||
(tui/key= msg "r")
|
(tui/key= msg "r")
|
||||||
[{:style-idx (:style-idx model) :frame 0 :done false}
|
[{:style-idx (:style-idx model) :frame 0 :done false}
|
||||||
(tui/tick 80)]
|
(tui/after 80 :spinner-frame)]
|
||||||
|
|
||||||
;; Handle tick
|
;; Handle spinner frame
|
||||||
(= msg :tick)
|
(= msg :spinner-frame)
|
||||||
(if (:done model)
|
(if (:done model)
|
||||||
[model nil]
|
[model nil]
|
||||||
(let [style-key (nth spinner-order (:style-idx model))
|
(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])
|
interval (get-in spinners [style-key :interval])
|
||||||
next-frame (mod (inc (:frame model)) (count frames))]
|
next-frame (mod (inc (:frame model)) (count frames))]
|
||||||
[(assoc model :frame next-frame)
|
[(assoc model :frame next-frame)
|
||||||
(tui/tick interval)]))
|
(tui/after interval :spinner-frame)]))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
[model nil]))
|
[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}
|
(tui/run {:init {:style-idx 0 :frame 0 :done false}
|
||||||
:update update-fn
|
:update update-fn
|
||||||
:view view
|
:view view
|
||||||
:init-cmd (tui/tick 80)}))
|
:init-cmd (tui/after 80 :spinner-frame)}))
|
||||||
```
|
```
|
||||||
|
|
||||||
### Output
|
### Output
|
||||||
@@ -498,10 +498,10 @@ tab: change style space: complete r: restart q: quit
|
|||||||
|
|
||||||
### Key Concepts
|
### 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
|
2. **Frame-based animation**: Cycle through an array of frames
|
||||||
3. **Multiple styles**: Store different spinner configurations
|
3. **Multiple styles**: Store different spinner configurations
|
||||||
4. **Stop animation**: Stop scheduling ticks when done
|
4. **Stop animation**: Stop scheduling timers when done
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -269,7 +269,7 @@ Commands are how your application performs side effects.
|
|||||||
| Command | Description |
|
| Command | Description |
|
||||||
|---------|-------------|
|
|---------|-------------|
|
||||||
| `tui/quit` | Exit the application |
|
| `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/batch cmd1 cmd2 ...)` | Run commands in parallel |
|
||||||
| `(tui/sequentially cmd1 cmd2 ...)` | Run commands in sequence |
|
| `(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")
|
(tui/key= msg "q")
|
||||||
[model tui/quit]
|
[model tui/quit]
|
||||||
|
|
||||||
;; Return tick command (async runtime only)
|
;; Return after command (async runtime only)
|
||||||
(tui/key= msg "s")
|
(tui/key= msg "s")
|
||||||
[{:started true} (tui/tick 1000)]
|
[{:started true} (tui/after 1000 :timer-tick)]
|
||||||
|
|
||||||
;; No command
|
;; No command
|
||||||
:else
|
:else
|
||||||
@@ -304,11 +304,11 @@ Commands are returned as the second element of the update function's return vect
|
|||||||
(tui/key= msg "q")
|
(tui/key= msg "q")
|
||||||
[model tui/quit]
|
[model tui/quit]
|
||||||
|
|
||||||
;; Handle tick message
|
;; Handle timer tick message
|
||||||
(= msg :tick)
|
(= msg :timer-tick)
|
||||||
(let [new-count (dec (:count model))]
|
(let [new-count (dec (:count model))]
|
||||||
(if (pos? new-count)
|
(if (pos? new-count)
|
||||||
[{:count new-count} (tui/tick 1000)]
|
[{:count new-count} (tui/after 1000 :timer-tick)]
|
||||||
[{:count 0 :done true} nil]))
|
[{:count 0 :done true} nil]))
|
||||||
|
|
||||||
:else
|
: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}
|
(tui/run {:init {:count 10 :done false}
|
||||||
:update update-fn
|
:update update-fn
|
||||||
:view view
|
:view view
|
||||||
:init-cmd (tui/tick 1000)})) ;; Start first tick
|
:init-cmd (tui/after 1000 :timer-tick)})) ;; Start first timer
|
||||||
```
|
```
|
||||||
|
|
||||||
## Configuration Options
|
## Configuration Options
|
||||||
|
|||||||
Reference in New Issue
Block a user