petitcarnets
Terminal user interfaces in the Elm architecture (model, update, view), for Rust, with no dependencies.
petitcarnets follows Bubble Tea v2 closely: the same loop, the same command and message names, and the same key strings. If you have written a Bubble Tea program in Go, the Rust version should read the way you expect.
Petits carnets: little notebooks.
Status
Early work, not yet published on crates.io. v0.0.1 has the runtime: the
Bubble Tea names, commands (batch, sequence, tick, every, tasks),
keys, window size, signals, and a terminal that is restored however the
program ends. Mouse, paste, a cell renderer and inline mode come in the
next releases; expect the API to grow.
Why
- No dependencies.
cargo treeprints one crate. The terminal is driven through a handful of libc calls in one audited module, the only place withunsafe. - Typed messages. Your messages are your own enum, matched exhaustively; no downcasting.
- No async runtime required. A command is a plain closure. Timers run on the event loop, not on threads, and an idle program does not wake up at all.
- Restores your terminal. Raw mode and every terminal mode are undone
on quit, on panic (in
updateor in a task), onSIGINTandSIGTERM; a real-terminal test checks each one in CI. - Testable. A headless backend runs a model with scripted keys and captures the screen, with no pseudo-terminal.
Example
use petitcarnets as tea;
;
Run the examples with cargo run --example counter (also picker,
spinner and lifecycle).
| Bubble Tea (Go) | petitcarnets |
|---|---|
tea.NewProgram(m).Run() |
tea::Program::new(m).run() |
case tea.KeyPressMsg: |
tea::Msg::KeyPress(k) => |
msg.String() == "ctrl+c" |
k == "ctrl+c" |
case tea.WindowSizeMsg: |
tea::Msg::WindowSize(size) => |
return m, tea.Quit |
return tea::quit() |
tea.Batch(a, b), tea.Sequence(a, b) |
tea::batch([a, b]), tea::sequence([a, b]) |
tea.Tick(d, fn), tea.Every(d, fn) |
tea::tick(d, f), tea::every(d, f) |
p.Send(msg) |
program.sender().send(msg) |
Platforms
Linux and macOS. Windows is planned for a later release.
Minimum supported Rust version: 1.85.
Licence
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT licence (LICENSE-MIT)
at your option.