Skip to main content

limit_tui/
lib.rs

1//! # limit-tui
2//!
3//! [![Crates.io](https://img.shields.io/crates/v/limit-tui.svg)](https://crates.io/crates/limit-tui)
4//! [![Docs.rs](https://docs.rs/limit-tui/badge.svg)](https://docs.rs/limit-tui)
5//! [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6//!
7//! **Terminal UI components with Virtual DOM rendering for Rust applications.**
8//!
9//! Build rich terminal interfaces with a component model, powered by
10//! [Ratatui](https://ratatui.rs/). Features declarative rendering, diff-based
11//! updates, and built-in syntax highlighting.
12//!
13//! ## Features
14//!
15//! - **Virtual DOM**: Component model with diff-based rendering
16//! - **Pre-built components**: Chat views, inputs, spinners, progress bars, select menus
17//! - **Syntax highlighting**: Built-in support for 150+ languages via Syntect
18//! - **Event handling**: Keyboard, mouse, and resize events
19//!
20//! ## Virtual DOM
21//!
22//! Build UIs with `VNode`:
23//!
24//! ```rust
25//! use limit_tui::vdom::VNode;
26//! use std::collections::HashMap;
27//!
28//! let ui = VNode::Element {
29//!     tag: "div".to_string(),
30//!     attrs: HashMap::new(),
31//!     children: vec![
32//!         VNode::Text("Hello, World!".to_string()),
33//!     ],
34//! };
35//! ```
36//!
37//! ### Diff-Based Updates
38//!
39//! The Virtual DOM computes minimal changes:
40//!
41//! ```rust
42//! use limit_tui::vdom::{diff, apply, VNode};
43//!
44//! let old_tree = VNode::Text("Hello".to_string());
45//! let new_tree = VNode::Text("Hello, World!".to_string());
46//!
47//! let patches = diff(&old_tree, &new_tree);
48//! // patches contains minimal changes to transform old → new
49//! ```
50//!
51//! ## Components
52//!
53//! | Component | Description |
54//! |-----------|-------------|
55//! | [`ChatView`] | Conversation display with role-based styling |
56//! | [`InputPrompt`] | Interactive text input with placeholder |
57//! | [`SelectPrompt`] | Single/multi-select menus |
58//! | [`Spinner`] | Loading spinner with label |
59//! | [`ProgressBar`] | Progress indicator |
60//!
61//! ## Syntax Highlighting
62//!
63//! ```rust,no_run
64//! use limit_tui::SyntaxHighlighter;
65//!
66//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
67//! let highlighter = SyntaxHighlighter::new()?;
68//!
69//! let code = highlighter.highlight_to_spans(r#"
70//! fn main() {
71//!     println!("Hello, World!");
72//! }
73//! "#, "rust")?;
74//!
75//! // Returns styled spans with syntax colors
76//! # Ok(())
77//! # }
78//! ```
79
80pub mod backend;
81pub mod components;
82pub mod layout;
83pub mod syntax;
84pub mod vdom;
85
86pub use backend::{render_vdom_to_ratatui, run_event_loop, RatatuiBackend};
87pub use components::{
88    ChatView, InputPrompt, InputResult, Message, ProgressBar, Role, SelectPrompt, SelectResult,
89    Spinner,
90};
91pub use layout::{AlignItems, FlexDirection, FlexStyle, FlexboxLayout, JustifyContent};
92pub use syntax::SyntaxHighlighter;
93pub use vdom::{apply, diff, render, Patch, VNode};