chai-tea

Crates.iochai-tea
lib.rschai-tea
version0.2.0
created_at2025-10-11 22:06:37.646135+00
updated_at2025-10-13 20:28:57.063416+00
descriptionA minimal Elm-style architecture for egui/eframe apps.
homepage
repositoryhttps://github.com/ryry0/chai-tea-rs
max_upload_size
id1878609
size134,294
Ryan Reyes (ryry0)

documentation

README

๐Ÿต chai-tea

a minimal Elm-style architecture for egui / eframe apps

Status: early-stage but functional โ€” now with async / background task support. API may change rapidly as development continues.


chai-tea lets you write GUI apps in the same clean loop youโ€™d use in The Elm Architecture (TEA):

use eframe::egui;

#[derive(Default)]
struct Model { counter: i32 }
enum Msg { Inc, Dec }

fn init() -> Model { Model { counter: 0 } }

fn update(m: Model, msg: Msg) -> Model {
    match msg {
        Msg::Inc => Model { counter: m.counter + 1, ..m },
        Msg::Dec => Model { counter: m.counter - 1, ..m },
    }
}

fn view(ctx: &egui::Context, m: &Model, tx: &mut Vec<Msg>) {
    egui::CentralPanel::default().show(ctx, |ui| {
        if ui.button("+").clicked() { tx.push(Msg::Inc); }
        if ui.button("โ€“").clicked() { tx.push(Msg::Dec); }
        ui.label(m.counter.to_string());
    });
}

fn main() -> eframe::Result<()> {
    chai_tea::brew(init, update, view)
}

add eframe to your dependencies, run it and youโ€™ve got a fully working counter app.

cargo run --example counter

๐Ÿงฉ example: async counters

A minimal demonstration of concurrent background workers, shared atomic state, and repaint-on-message behavior is included under

cargo run --example multicounter

Each counter runs in its own thread and reports back through ChaiSender, automatically triggering redraws.

โœจ features

  • ๐Ÿƒ Pure Elm-style loop โ€” deterministic, functional, and testable
  • ๐Ÿงต Async commands via brew_async, SyncState, and ChaiSender
    • spawn background threads or async tasks
    • send messages back safely
    • UI automatically repaints on message arrival
  • ๐ŸŒ Native + (soon) WASM support
  • ๐Ÿชถ Tiny, dependency-light core
  • โ˜• Ergonomic aliases โ€” brew = run, brew_async = run_async

๐Ÿซ– possible roadmap

  • async / background command support
  • fixed-timestep threaded simulation variant
  • wasm runner (chai_tea::run_web)
  • macro sugar: #[chai_app]
  • theme system (chai-latte someday?)
  • time travel debugger?
Commit count: 0

cargo fmt