eye-declare
A declarative inline TUI rendering library for Rust, built on Ratatui.
eye-declare provides a React-like component model for building terminal UIs that render inline — content grows into the terminal's native scrollback rather than taking over the full screen. Designed for CLI tools, AI assistants, and interactive prompts where output accumulates and earlier results should remain visible.

Status
eye-declare is in early development; expect breaking changes.
Coming changes:
- Better HStack layout options
- More ergonomic "leaf" API
Quick Start
use ;
async
The element! Macro
The element! macro is the primary way to build UIs. It provides JSX-like syntax for composing component trees:
Syntax reference
| Syntax | Description |
|---|---|
Component(prop: value) |
Construct with props (struct field init) |
Component { ... } |
Component with children |
Component(props) { children } |
Both |
"text" |
String literal — auto-wrapped as TextBlock |
key: expr |
Special prop for stable identity across rebuilds |
#(if cond { ... }) |
Conditional children |
#(if let pat = expr { ... }) |
Pattern-matching conditional |
#(for pat in iter { ... }) |
Loop children |
#(expr) |
Splice a pre-built Elements value inline |
Components
Components are the building blocks. Props live on &self (immutable, set by parent). Internal state lives in the associated State type (mutable, framework-managed via automatic dirty tracking).
use Component;
use ;
use Paragraph;
Then use it in a view:
element!
Composite Components
Components can generate child trees via the children() method. The slot parameter carries externally-provided children (like React's props.children):
Usage with element!:
element!
Three patterns:
- Pass through (default) — VStack, HStack accept external children as-is
- Generate own tree — a Spinner builds its own frame + label layout internally
- Wrap slot — a Card wraps external children in a header + border
Lifecycle Hooks
Components declare effects via lifecycle(). The framework manages registration and cleanup:
Available hooks:
| Hook | Fires when |
|---|---|
use_interval(duration, handler) |
Periodically, at the given duration |
use_mount(handler) |
Once, after the component is first built |
use_unmount(handler) |
Once, when the component is removed |
use_autofocus() |
Requests focus when the component mounts |
Layout
Vertical stacking is the default. HStack provides horizontal layout with width constraints:
use ;
use Fixed;
Components can declare content_inset() for borders and padding — children render inside the inset area while the component draws chrome in the full area.
Reconciliation
Elements are matched by key (stable identity) or position (implicit). State is preserved across rebuilds when nodes are reused:
element!
Application
Application owns your state and manages the render loop. Handle sends updates from any thread or async task:
let = builder
.state
.view
.build?;
// Non-interactive: exits when handle is dropped and effects stop
app.run.await?;
// Interactive: raw mode, event handling, Ctrl+C
app.run_interactive.await?;
Multiple handle updates between frames are batched into a single rebuild.
Committed Scrollback
For long-running apps, content that scrolls into terminal scrollback can be evicted from state via an on_commit callback:
builder
.state
.view
.on_commit
.build?;
This is an opt-in performance optimization. Without it, the framework handles all content normally.
Imperative API
For direct control over the render loop, use InlineRenderer:
use ;
let mut renderer = new;
let spinner_id = renderer.push;
// Mutate state, render, write to stdout
sleep;
renderer.tick;
let output = renderer.render;
stdout.write_all?;
// Declarative subtrees via rebuild
let container = renderer.push;
renderer.rebuild;
See the terminal_demo and lifecycle examples for complete sync event loop patterns.
Built-in Components
| Component | Description |
|---|---|
TextBlock |
Styled text with display-time word wrapping. Supports Line/Span children for multi-styled lines. |
Spinner |
Animated Braille spinner with auto-tick. Shows a checkmark when .done(). |
Markdown |
Headings, bold, italic, inline code, code blocks, and lists. |
VStack |
Vertical container — children stack top-to-bottom. |
HStack |
Horizontal container — children lay left-to-right with WidthConstraint-based layout. |
Examples
Architecture
Application State + view function + async event loop
InlineRenderer Rendering, reconciliation, layout, diffing, scrollback
ratatui-core Buffer, Cell, Style, Widget primitives
crossterm Terminal I/O, event types
Inline rendering model
eye-declare uses an inline rendering model — content grows downward into the terminal's native scrollback, like standard CLI output. This is fundamentally different from full-screen TUI frameworks (ratatui's Terminal, tui-realm, cursive) that redraw a fixed viewport.
The tradeoff is deliberate. Inline rendering is the right model for AI assistants, build tools, and interactive prompts where output accumulates and earlier results should persist in scrollback for the user to review.
How it works:
-
Reconciliation matches new elements against existing nodes by key or position. State is preserved when nodes are reused, so animations continue seamlessly and internal component state survives rebuilds.
-
Layout measures each node's desired height (with word wrapping computed at render time) and allocates widths for horizontal containers. Content insets allow components to declare border/padding chrome while children render inside.
-
Rendering produces a Ratatui
Bufferfor each frame. TheInlineRendererdiffs against the previous frame and emits only changed cells as ANSI escape sequences, wrapped in DEC synchronized output (?2026h/l) to prevent tearing. -
Growth is handled by emitting newlines to claim new terminal rows before writing content. Old rows naturally scroll into terminal scrollback.
Scrollback handling: When content height exceeds the terminal height, the terminal scrolls rows into scrollback. The framework tracks terminal height and filters diff output to only address visible rows. The on_commit callback provides an additional optimization by evicting committed content from application state entirely.
Crate Structure
crates/
eye_declare/ Main library
eye_declare_macros/ element! proc macro
The macro is behind the macros feature flag (enabled by default).
License
MIT