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
+17 -40
View File
@@ -8,10 +8,11 @@ A terminal user interface framework for Clojure, inspired by [Bubbletea](https:/
- **Elm Architecture** - Predictable state management with `init`, `update`, and `view`
- **Hiccup Views** - Declarative UI with familiar Clojure syntax
- **Two Runtimes** - Full async (`tui.core`) or simple sync (`tui.simple` for Babashka)
- **Async Commands** - Timers, batched operations, and custom async functions
- **Rich Styling** - Colors (16, 256, true color), bold, italic, underline, and more
- **Layout System** - Rows, columns, and boxes with borders
- **Input Handling** - Full keyboard support including arrows, function keys, and modifiers
- **Babashka Compatible** - Fast startup with Babashka or full Clojure
## Quick Start
@@ -27,14 +28,14 @@ Add to your `deps.edn`:
```clojure
(ns myapp.core
(:require [tui.simple :as tui]))
(:require [tui.core :as tui]))
(defn update-fn [model msg]
(if (tui/key= msg "q")
[model tui/quit]
[model nil]))
(defn view [model]
(defn view [model _size]
[:col
[:text {:fg :cyan :bold true} "Hello, TUI!"]
[:text {:fg :gray} "Press q to quit"]])
@@ -54,7 +55,7 @@ Press q to quit
```clojure
(ns myapp.counter
(:require [tui.simple :as tui]))
(:require [tui.core :as tui]))
(defn update-fn [model msg]
(cond
@@ -64,7 +65,7 @@ Press q to quit
(tui/key= msg "r") [0 nil]
:else [model nil]))
(defn view [model]
(defn view [model _size]
[:col
[:box {:border :rounded :padding [0 2]}
[:text {:fg :yellow :bold true} (str "Count: " model)]]
@@ -139,9 +140,16 @@ Async HTTP requests with loading states.
bb http
```
### Running with Full Clojure
### Running Examples
For full async support (core.async), run with Clojure:
Run examples with Babashka (recommended for fast startup):
```bash
bb counter
bb timer
```
Or with full Clojure:
```bash
clojure -A:dev -M -m examples.counter
@@ -167,37 +175,7 @@ The application follows the Elm Architecture:
1. **Model** - Your application state (any Clojure data structure)
2. **Update** - A pure function `(fn [model msg] [new-model cmd])` that handles messages
3. **View** - A pure function `(fn [model] hiccup)` that renders the UI
## Two Runtimes
### `tui.simple` - Synchronous (Babashka-compatible)
Best for simple applications. No async support, but works with Babashka.
```clojure
(require '[tui.simple :as tui])
(tui/run {:init model :update update-fn :view view-fn})
```
### `tui.core` - Asynchronous (Full Clojure)
Full-featured runtime with async commands like timers and batched operations.
```clojure
(require '[tui.core :as tui])
(defn update-fn [model msg]
(case msg
:tick [(update model :seconds inc) (tui/tick 1000)]
[model nil]))
(tui/run {:init {:seconds 0}
:update update-fn
:view view-fn
:init-cmd (tui/tick 1000)})
```
3. **View** - A pure function `(fn [model size] hiccup)` that renders the UI, where `size` is `{:width w :height h}`
## Hiccup View Elements
@@ -236,8 +214,7 @@ Commands are returned from your `update` function to trigger side effects:
```
src/
tui/
core.clj # Full async runtime (core.async)
simple.clj # Simple sync runtime (Babashka-compatible)
core.clj # Main runtime (Elm architecture + async commands)
render.clj # Hiccup → ANSI
terminal.clj # Raw mode, input/output
input.clj # Key parsing