Skip to main content

tui_dispatch_components/
lib.rs

1//! Pre-built UI components for tui-dispatch
2//!
3//! This crate provides reusable TUI components that integrate with tui-dispatch patterns.
4//! Components implement the `Component<A>` trait and emit actions via callback functions
5//! passed through Props.
6//!
7//! # Components
8//!
9//! - [`SelectList`] - Scrollable selection list with keyboard navigation
10//! - [`ScrollView`] - Scrollable view for pre-wrapped lines
11//! - [`StatusBar`] - Left/center/right status bar with hints
12//! - [`TextInput`] - Single-line text input with cursor
13//! - [`TreeView`] - Hierarchical tree view with selection
14//! - [`Modal`] - Overlay with dimmed background
15//!
16//! # Styling
17//!
18//! All components use unified styling objects:
19//! - [`SelectListStyle`] - Styling for SelectList (base, selection, scrollbar)
20//! - [`ScrollViewStyle`] - Styling for ScrollView (base, scrollbar)
21//! - [`StatusBarStyle`] - Styling for StatusBar (base, hints, separators)
22//! - [`TextInputStyle`] - Styling for TextInput (base, placeholder, cursor)
23//! - [`TreeViewStyle`] - Styling for TreeView (base, selection, branches)
24//! - [`ModalStyle`] - Styling for Modal (base, dimming)
25//!
26//! Common types are available in the [`style`] module.
27//! Routed command name constants are available in the [`commands`] module.
28//!
29//! # Example
30//!
31//! ```ignore
32//! use tui_dispatch_components::{
33//!     Line, SelectList, SelectListBehavior, SelectListProps, SelectListStyle,
34//! };
35//! use std::rc::Rc;
36//!
37//! // In your render function:
38//! let items: Vec<Line> = state.items.iter().map(|s| Line::raw(s)).collect();
39//! let render_item = |item: &Line| item.clone();
40//! let mut list = SelectList::default();
41//! list.render(frame, area, SelectListProps {
42//!     items: &items,
43//!     count: items.len(),
44//!     selected: state.selected,
45//!     is_focused: state.focus == Focus::List,
46//!     style: SelectListStyle::default(),
47//!     behavior: SelectListBehavior::default(),
48//!     on_select: Rc::new(|i| Action::Select(i)),
49//!     render_item: &render_item,
50//! });
51//! ```
52
53#[cfg(target_arch = "wasm32")]
54extern crate tinycrossterm as crossterm;
55
56pub mod commands;
57mod host;
58mod modal;
59mod runtime;
60mod scroll_view;
61mod select_list;
62mod status_bar;
63pub mod style;
64mod text_input;
65mod tree_view;
66
67pub use host::{
68    ComponentDebugEntry, ComponentDebugState, ComponentHost, ComponentInput, HostLifecycleError,
69    InteractiveComponent, Mounted, MountedComponentInfo, PropsFactory,
70};
71pub use modal::{centered_rect, Modal, ModalBehavior, ModalCloseCallback, ModalProps, ModalStyle};
72pub use ratatui::text::Line;
73pub use runtime::{ComponentHostRuntime, HostedRuntime, HostedRuntimeParts, RuntimeHostExt};
74pub use scroll_view::{
75    LinesScroller, ScrollView, ScrollViewBehavior, ScrollViewCallback, ScrollViewProps,
76    ScrollViewRenderProps, ScrollViewStyle, VisibleRange,
77};
78pub use select_list::{
79    SelectList, SelectListBehavior, SelectListCallback, SelectListProps, SelectListRenderProps,
80    SelectListStyle,
81};
82pub use status_bar::{
83    StatusBar, StatusBarHint, StatusBarItem, StatusBarProps, StatusBarSection, StatusBarStyle,
84};
85pub use style::{
86    highlight_substring, BaseStyle, BorderStyle, Color, ComponentStyle, Modifier, Padding,
87    ScrollbarStyle, SelectionStyle, Style,
88};
89pub use text_input::{
90    TextInput, TextInputCallback, TextInputCursorCallback, TextInputProps, TextInputRenderProps,
91    TextInputStyle,
92};
93pub use tree_view::{
94    TreeBranchMode, TreeBranchStyle, TreeNode, TreeNodeRender, TreeSelectCallback,
95    TreeToggleCallback, TreeView, TreeViewBehavior, TreeViewProps, TreeViewRenderProps,
96    TreeViewStyle,
97};
98
99/// Prelude for convenient imports
100pub mod prelude {
101    pub use crate::commands;
102
103    pub use crate::{
104        centered_rect, BaseStyle, BorderStyle, ComponentStyle, LinesScroller, Modal, ModalBehavior,
105        ModalCloseCallback, ModalProps, ModalStyle, Padding, ScrollView, ScrollViewBehavior,
106        ScrollViewCallback, ScrollViewProps, ScrollViewRenderProps, ScrollViewStyle,
107        ScrollbarStyle, SelectList, SelectListBehavior, SelectListCallback, SelectListProps,
108        SelectListRenderProps, SelectListStyle, SelectionStyle, StatusBar, StatusBarHint,
109        StatusBarItem, StatusBarProps, StatusBarSection, StatusBarStyle, TextInput,
110        TextInputCallback, TextInputCursorCallback, TextInputProps, TextInputRenderProps,
111        TextInputStyle, TreeBranchMode, TreeBranchStyle, TreeNode, TreeNodeRender,
112        TreeSelectCallback, TreeToggleCallback, TreeView, TreeViewBehavior, TreeViewProps,
113        TreeViewRenderProps, TreeViewStyle, VisibleRange,
114    };
115
116    pub use crate::{
117        ComponentDebugEntry, ComponentDebugState, ComponentHost, ComponentInput,
118        HostLifecycleError, HostedRuntime, InteractiveComponent, Mounted, MountedComponentInfo,
119        PropsFactory, RuntimeHostExt,
120    };
121
122    pub use ratatui::style::{Color, Modifier, Style};
123    pub use ratatui::text::Line;
124}