update docs

This commit is contained in:
2026-01-22 10:50:26 -05:00
parent 95b53f7533
commit 0e40fe01d7
14 changed files with 57 additions and 508 deletions
+10 -27
View File
@@ -14,8 +14,7 @@ Add the library to your `deps.edn`:
### Requirements
- **Clojure 1.11+** for full async runtime (`tui.core`)
- **Babashka** for simple sync runtime (`tui.simple`)
- **Babashka** (recommended) or **Clojure 1.11+**
- A terminal that supports ANSI escape codes (most modern terminals)
## Your First Application
@@ -41,7 +40,7 @@ Create `src/myapp/core.clj`:
```clojure
(ns myapp.core
(:require [tui.simple :as tui]))
(:require [tui.core :as tui]))
;; 1. Model - the application state
(def initial-model
@@ -58,8 +57,8 @@ Create `src/myapp/core.clj`:
:else
[model nil]))
;; 3. View - render the model as hiccup
(defn view [{:keys [message]}]
;; 3. View - render the model as hiccup (receives model and terminal size)
(defn view [{:keys [message]} _size]
[:col
[:text {:fg :cyan :bold true} message]
[:space {:height 1}]
@@ -120,7 +119,7 @@ Clojure TUI uses the [Elm Architecture](https://guide.elm-lang.org/architecture/
2. **Update**: A pure function that takes the current model and a message, returning a vector of `[new-model command]`.
3. **View**: A pure function that takes the model and returns a hiccup data structure representing the UI.
3. **View**: A pure function that takes the model and terminal size, returning a hiccup data structure representing the UI.
### The Flow
@@ -198,7 +197,7 @@ Let's build something more interactive: a counter.
```clojure
(ns myapp.counter
(:require [tui.simple :as tui]))
(:require [tui.core :as tui]))
(defn update-fn [model msg]
(cond
@@ -220,7 +219,7 @@ Let's build something more interactive: a counter.
:else [model nil]))
(defn view [count]
(defn view [count _size]
[:col
[:box {:border :rounded :padding [0 2]}
[:row
@@ -315,7 +314,7 @@ Commands are returned as the second element of the update function's return vect
:else
[model nil]))
(defn view [{:keys [count done]}]
(defn view [{:keys [count done]} _size]
[:col
(if done
[:text {:fg :green :bold true} "Time's up!"]
@@ -329,22 +328,6 @@ Commands are returned as the second element of the update function's return vect
:init-cmd (tui/tick 1000)})) ;; Start first tick
```
## Choosing a Runtime
### `tui.simple` - For Babashka and Simple Apps
- Works with Babashka
- Synchronous (blocking) input
- No async commands (tick, batch, etc.)
- Lower resource usage
### `tui.core` - For Complex Applications
- Requires full Clojure with core.async
- Async input handling
- Full command support (tick, batch, sequentially)
- Better for animations and background tasks
## Configuration Options
The `run` function accepts these options:
@@ -353,9 +336,9 @@ The `run` function accepts these options:
|--------|-------------|---------|
| `:init` | Initial model (required) | - |
| `:update` | Update function (required) | - |
| `:view` | View function (required) | - |
| `:view` | View function `(fn [model size] hiccup)` (required) | - |
| `:init-cmd` | Initial command to run | `nil` |
| `:fps` | Frames per second (core only) | `60` |
| `:fps` | Frames per second | `60` |
| `:alt-screen` | Use alternate screen buffer | `true` |
### Alternate Screen