hojicha_runtime/
lib.rs

1//! # Hojicha Runtime
2//!
3//! Event handling and async runtime for Hojicha TUI applications.
4//!
5//! This crate provides the runtime infrastructure for handling events,
6//! managing async operations, and running the main application loop.
7//!
8//! ## Core Components
9//!
10//! - **Program**: Main application runtime and event loop
11//! - **Event Processing**: Priority-based event handling with backpressure
12//! - **Async Support**: Tokio-based async command execution
13//! - **Subscriptions**: Stream-based event sources
14//! - **Error Resilience**: Panic recovery and error handling
15//!
16//! ## Features
17//!
18//! - Priority event queue with automatic scaling
19//! - Resilient input handling with panic recovery
20//! - Safe mutex operations that recover from poison
21//! - Metrics and monitoring support
22//! - Terminal management and restoration
23
24#![warn(missing_docs)]
25
26// Note: Event types are in hojicha-core since they're fundamental to the Model trait
27
28// Program and runtime
29pub mod program;
30pub use program::{MouseMode, Program, ProgramOptions};
31
32// Shared runtime infrastructure
33pub mod shared_runtime;
34
35// Async support
36pub mod async_handle;
37pub mod stream_builders;
38pub mod subscription;
39
40// Event processing infrastructure
41pub mod metrics;
42pub mod priority_queue;
43pub mod queue_scaling;
44
45// Testing utilities
46pub mod safe_priority;
47pub mod testing;
48
49// Error resilience
50pub mod panic_handler;
51pub mod panic_recovery;
52pub mod panic_utils;
53pub mod resilient_input;
54pub mod resource_limits;
55pub mod safe_mutex;
56
57// String-based rendering
58pub mod string_renderer;
59
60// Re-export from core
61pub use hojicha_core::event::{Event, Key, KeyEvent, KeyModifiers, MouseEvent, WindowSize};
62
63// Re-export runtime types
64pub use async_handle::AsyncHandle;
65pub use subscription::Subscription;
66
67// Re-export program components
68pub use program::{
69    CommandExecutor, EventProcessor, EventStats, FpsLimiter, PriorityConfig,
70    PriorityEventProcessor, TerminalConfig, TerminalManager,
71};
72
73/// Prelude for convenient imports
74///
75/// This module provides the essential runtime types for Hojicha applications.
76/// Import everything with:
77///
78/// ```
79/// use hojicha_runtime::prelude::*;
80/// ```
81///
82/// ## Included Items
83///
84/// ### Program & Configuration
85/// - [`Program`] - The main application runtime
86/// - [`ProgramOptions`] - Configuration for the program
87/// - [`MouseMode`] - Mouse tracking options
88///
89/// ### Async Support
90/// - [`AsyncHandle`] - Handle for cancellable async operations
91/// - [`Subscription`] - Stream subscription handle
92///
93/// ### Stream Builders
94/// - [`interval_stream()`] - Create periodic event streams
95/// - [`timeout_stream()`] - Create timeout streams
96/// - [`delayed_stream()`] - Create delayed streams
97pub mod prelude {
98    // Program and configuration
99    pub use crate::program::{MouseMode, Program, ProgramOptions};
100
101    // Async support
102    pub use crate::async_handle::AsyncHandle;
103    pub use crate::subscription::Subscription;
104
105    // Stream builders for common patterns
106    pub use crate::stream_builders::{delayed_stream, interval_stream, timeout_stream};
107
108    // Re-export essential event types from core
109    pub use hojicha_core::event::{Event, Key, KeyEvent, KeyModifiers, MouseEvent, WindowSize};
110}