Architecture
Module Overview
leaf is written in Rust (Edition 2021) and organized into these modules:
| Module | Responsibility |
|---|---|
main.rs | CLI parsing, input handling, TUI setup |
cli.rs | Command-line argument definitions |
config.rs | Configuration file reading |
app/ | Application state (document, TOC, search, pickers) |
markdown/ | Parsing, rendering, LaTeX, Mermaid, tables, TOC extraction |
render/ | TUI layout with ratatui |
runtime.rs | Event loop, keyboard/mouse handling |
theme.rs | Theme presets and color definitions |
editor.rs | Editor detection and spawning |
terminal.rs | Raw terminal mode lifecycle |
update.rs | Self-update with SHA256 verification |
Key Dependencies
- ratatui — terminal UI framework
- crossterm — cross-platform terminal handling
- pulldown-cmark — Markdown parsing
- syntect — syntax highlighting
- mmdflux — Mermaid diagram rendering
- unicodeit — LaTeX-to-Unicode conversion
Event Loop
The main event loop in runtime.rs runs at ~20 FPS (50ms ticks):
- Poll async file picker loading
- Check file changes (watch mode)
- Handle keyboard/mouse input
- Redraw the TUI
- Handle terminal resize
Building
cargo build --release
cargo test