envision/
lib.rs

1#![warn(missing_docs)]
2
3//! # Envision
4//!
5//! A ratatui framework for collaborative TUI development with headless testing support.
6//!
7//! Envision provides a custom `CaptureBackend` that implements ratatui's `Backend` trait,
8//! enabling you to:
9//!
10//! - Capture rendered frames as inspectable text or structured data
11//! - Track frame history and compute diffs between renders
12//! - Annotate widgets with semantic information
13//! - Simulate user input for testing
14//! - Run applications in headless mode for CI/testing
15//!
16//! ## Quick Start
17//!
18//! ```rust,no_run
19//! use envision::backend::CaptureBackend;
20//! use ratatui::Terminal;
21//! use ratatui::widgets::Paragraph;
22//!
23//! // Create a headless terminal
24//! let backend = CaptureBackend::new(80, 24);
25//! let mut terminal = Terminal::new(backend).unwrap();
26//!
27//! // Render something
28//! terminal.draw(|frame| {
29//!     frame.render_widget(Paragraph::new("Hello, Envision!"), frame.area());
30//! }).unwrap();
31//!
32//! // Capture the output
33//! let output = terminal.backend().to_string();
34//! println!("{}", output);
35//! ```
36//!
37//! ## Input Simulation
38//!
39//! ```rust
40//! use envision::input::{EventQueue, KeyCode};
41//!
42//! let mut queue = EventQueue::new();
43//! queue.type_str("hello");
44//! queue.enter();
45//!
46//! // Events can be consumed by your app's event loop
47//! while let Some(event) = queue.pop() {
48//!     // handle event...
49//! }
50//! ```
51
52pub mod adapter;
53pub mod annotation;
54pub mod app;
55pub mod backend;
56pub mod component;
57pub mod harness;
58pub mod input;
59
60// Re-export commonly used types
61pub use adapter::DualBackend;
62pub use annotation::{Annotate, Annotation, AnnotationRegistry, WidgetType};
63pub use app::{
64    App, AsyncCommandHandler, AsyncRuntime, AsyncRuntimeConfig, Command, DebounceSubscription,
65    FilterSubscription, IntervalImmediateSubscription, Runtime, RuntimeConfig, Subscription,
66    SubscriptionExt, TakeSubscription, TerminalEventSubscription, ThrottleSubscription,
67    TickSubscription, TimerSubscription,
68};
69pub use backend::{CaptureBackend, EnhancedCell, FrameSnapshot};
70pub use component::{
71    Component, Focusable, InputField, InputFieldState, InputMessage, InputOutput, ListMessage,
72    ListOutput, SelectableList, SelectableListState, Toggleable,
73};
74pub use harness::{Assertion, AsyncTestHarness, Snapshot, TestHarness};
75pub use input::{EventQueue, SimulatedEvent};
76
77/// Prelude module for convenient imports
78pub mod prelude {
79    pub use crate::adapter::DualBackend;
80    pub use crate::annotation::{Annotate, Annotation, AnnotationRegistry, RegionInfo, WidgetType};
81    pub use crate::app::{
82        App, AsyncCommandHandler, AsyncRuntime, AsyncRuntimeConfig, Command, Runtime,
83        RuntimeConfig, Subscription, SubscriptionExt, TickSubscription, TimerSubscription, Update,
84    };
85    pub use crate::backend::{CaptureBackend, EnhancedCell, FrameSnapshot, OutputFormat};
86    pub use crate::component::{
87        Component, Focusable, InputField, InputFieldState, InputMessage, InputOutput, ListMessage,
88        ListOutput, SelectableList, SelectableListState, Toggleable,
89    };
90    pub use crate::harness::{
91        Assertion, AssertionError, AsyncTestHarness, Snapshot, SnapshotFormat, TestHarness,
92    };
93    pub use crate::input::{EventQueue, KeyCode, KeyModifiers, SimulatedEvent};
94    pub use ratatui::prelude::*;
95}