1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
//! Declarative inline TUI rendering for Rust, built on [Ratatui](https://ratatui.rs).
//!
//! eye_declare provides a React-like component model for terminal UIs that render
//! **inline** — content grows downward into the terminal's native scrollback rather
//! than taking over the full screen. This makes it ideal for CLI tools, AI assistants,
//! build systems, and interactive prompts where earlier output should remain visible.
//!
//! # Quick start
//!
//! ```ignore
//! use eye_declare::{element, Application, Elements, Spinner};
//!
//! struct State { messages: Vec<String>, loading: bool }
//!
//! fn view(state: &State) -> Elements {
//! element! {
//! #(for (i, msg) in state.messages.iter().enumerate() {
//! Text(key: format!("msg-{i}")) { #(msg.clone()) }
//! })
//! #(if state.loading {
//! Spinner(key: "loading", label: "Thinking...")
//! })
//! }
//! }
//!
//! #[tokio::main]
//! async fn main() -> std::io::Result<()> {
//! let (mut app, handle) = Application::builder()
//! .state(State { messages: vec![], loading: true })
//! .view(view)
//! .build()?;
//!
//! tokio::spawn(async move {
//! handle.update(|s| s.messages.push("Hello!".into()));
//! handle.update(|s| s.loading = false);
//! });
//!
//! app.run().await
//! }
//! ```
//!
//! # Core concepts
//!
//! - **[`#[component]`](macro@component) + [`#[props]`](macro@props)** — Define
//! components as functions. Props are a struct with `#[props]`; the function
//! receives props, optional state, hooks, and children, returning an [`Elements`]
//! tree. Hooks declare behavioral capabilities (events, focus, intervals).
//!
//! - **[`Elements`]** — A list of component descriptions returned by view functions.
//! The framework reconciles the new list against the existing tree, preserving
//! state for reused nodes.
//!
//! - **[`element!`]** — A JSX-like proc macro for building `Elements` declaratively.
//! Supports props, children, keys, conditionals (`#(if ...)`), loops (`#(for ...)`),
//! and splicing pre-built `Elements` (`#(expr)`).
//!
//! - **[`Application`]** — Owns your state and manages the render loop.
//! [`Handle`] lets you send state updates from any thread or async task.
//!
//! - **[`InlineRenderer`]** — The lower-level rendering engine for when you need
//! direct control over the render loop (sync code, embedding, custom event loops).
//!
//! # Built-in components
//!
//! | Component | Description |
//! |-----------|-------------|
//! | [`Text`] | Styled text with word wrapping (data children: [`Span`]) |
//! | [`Spinner`] | Animated spinner with auto-tick via lifecycle hooks |
//! | [`Markdown`] | Headings, bold, italic, inline code, code blocks, lists |
//! | [`View`] | Unified layout container with optional borders, padding, and background |
//! | [`Canvas`] | Raw buffer rendering via a user-provided closure |
//! | [`VStack`] | Vertical container — children stack top-to-bottom |
//! | [`HStack`] | Horizontal container with [`WidthConstraint`]-based layout |
//!
//! # Layout
//!
//! Vertical stacking is the default. [`HStack`] provides horizontal layout where
//! children declare their width via [`WidthConstraint::Fixed`] or [`WidthConstraint::Fill`].
//! Components can declare [`Insets`] for border/padding chrome — children render inside
//! the inset area while the component draws its chrome in the full area.
//!
//! # Lifecycle hooks
//!
//! Components declare effects using the [`Hooks`] API:
//!
//! - [`Hooks::use_interval`] — periodic callback (e.g., animation)
//! - [`Hooks::use_mount`] — fires once after the component is built
//! - [`Hooks::use_unmount`] — fires when the component is removed
//! - [`Hooks::use_autofocus`] — request focus on mount
//! - [`Hooks::use_focus_scope`] — confine Tab cycling to this subtree
//! - [`Hooks::provide_context`] — make a value available to descendants
//! - [`Hooks::use_context`] — read a value provided by an ancestor
//!
//! # Context
//!
//! The context system lets ancestor components provide values to their
//! descendants without prop-drilling. Register root-level contexts via
//! [`ApplicationBuilder::with_context`], or have components provide
//! them via [`Hooks::provide_context`] in their component function.
//! Descendants read context values with [`Hooks::use_context`].
//!
//! This is commonly used with [`Application::run_loop`] to give
//! components access to an app-domain event channel:
//!
//! ```ignore
//! let (tx, mut rx) = tokio::sync::mpsc::channel(32);
//! let (mut app, handle) = Application::builder()
//! .state(MyState::default())
//! .view(my_view)
//! .with_context(tx)
//! .build()?;
//!
//! let h = handle.clone();
//! tokio::spawn(async move {
//! while let Some(event) = rx.recv().await {
//! match event {
//! AppEvent::Submit(val) => h.update(|s| s.result = val),
//! AppEvent::Quit => { h.exit(); break; }
//! }
//! }
//! });
//!
//! app.run_loop().await?;
//! ```
//!
//! # Feature flags
//!
//! | Flag | Default | Description |
//! |------|---------|-------------|
//! | `macros` | yes | Enables the [`element!`] proc macro via `eye_declare_macros` |
/// Application wrapper, builder, handle, and control flow types.
///
/// See [`Application`] for the high-level entry point.
/// Traits and types for the `element!` macro's child collection system.
///
/// Most users won't interact with this module directly — it powers the
/// `element!` macro's ability to type-check parent-child relationships
/// at compile time. See [`ChildCollector`] if you're building a component
/// that accepts data children (like [`Text`](crate::Text) accepts [`Span`](crate::Span)s).
/// The [`Component`] trait (framework-internal) and built-in containers
/// ([`VStack`], [`HStack`], [`Column`]).
/// Built-in components: [`Text`](components::text::Text),
/// [`Spinner`](components::spinner::Spinner),
/// [`Markdown`](components::markdown::Markdown), and
/// [`View`](components::view::View).
/// The [`Elements`] list and [`ElementHandle`] for building component trees.
/// Lifecycle hooks for declaring component effects.
///
/// See [`Hooks`] for the API used inside `#[component]` functions.
/// The [`InlineRenderer`] — low-level inline rendering engine.
///
/// Use this when you need direct control over the render loop
/// rather than the higher-level [`Application`] wrapper.
/// The [`Insets`] type for declaring content padding and border chrome.
/// Cell measurement type for component props. See [`Cells`].
pub
pub
pub
pub
pub
pub
pub use ;
pub use Cells;
pub use ;
pub use ;
pub use Canvas;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Viewport;
pub use ;
pub use Hooks;
pub use InlineRenderer;
pub use Insets;
pub use ;
pub use TypedBuilder;
// Re-exports for component props
/// Re-exported from `ratatui_widgets` for use with [`View::border`].
pub use BorderType;
/// Declarative element tree macro.
///
/// Builds an [`Elements`] list from JSX-like syntax. This is the primary
/// way to describe UI trees in eye_declare.
///
/// # Syntax
///
/// ```ignore
/// element! {
/// // Component with props
/// Spinner(label: "Loading...", done: false)
///
/// // Component with children (slot)
/// VStack {
/// "hello"
/// }
///
/// // Key for stable identity across rebuilds
/// Markdown(key: "intro", source: "# Hello".into())
///
/// // String literal shorthand (becomes a Text)
/// "Some plain text"
///
/// // Conditional children
/// #(if state.loading {
/// Spinner(label: "Please wait...")
/// })
///
/// // Loop children
/// #(for item in &state.items {
/// Markdown(key: item.id.clone(), source: item.text.clone())
/// })
///
/// // Splice pre-built Elements
/// #(footer_elements(state))
/// }
/// ```
///
/// The macro returns an [`Elements`] value. View functions typically
/// return this directly:
///
/// ```ignore
/// fn my_view(state: &MyState) -> Elements {
/// element! {
/// Spinner(label: "working...")
/// }
/// }
/// ```
pub use component;
pub use element;
pub use props;