Architecture

Module Overview

leaf is written in Rust (Edition 2021) and organized into these modules:

ModuleResponsibility
main.rsCLI parsing, input handling, TUI setup
cli.rsCommand-line argument definitions
config.rsConfiguration file reading
app/Application state (document, TOC, search, pickers)
markdown/Parsing, rendering, LaTeX, Mermaid, tables, TOC extraction
render/TUI layout with ratatui
runtime.rsEvent loop, keyboard/mouse handling
theme.rsTheme presets and color definitions
editor.rsEditor detection and spawning
terminal.rsRaw terminal mode lifecycle
update.rsSelf-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):

  1. Poll async file picker loading
  2. Check file changes (watch mode)
  3. Handle keyboard/mouse input
  4. Redraw the TUI
  5. Handle terminal resize

Building

cargo build --release
cargo test