Skip to main content

ftui_runtime/
lib.rs

1#![forbid(unsafe_code)]
2
3//! FrankenTUI Runtime
4//!
5//! This crate provides the runtime components that tie together the core,
6//! render, and layout crates into a complete terminal application framework.
7//!
8//! # Key Components
9//!
10//! - [`TerminalWriter`] - Unified terminal output coordinator with inline mode support
11//! - [`LogSink`] - Line-buffered writer for sanitized log output
12//! - [`Program`] - Bubbletea/Elm-style runtime for terminal applications
13//! - [`Model`] - Trait for application state and behavior
14//! - [`Cmd`] - Commands for side effects
15//! - [`Subscription`] - Trait for continuous event sources
16//! - [`Every`] - Built-in tick subscription
17//!
18//! # Role in FrankenTUI
19//! `ftui-runtime` is the orchestrator. It consumes input events from
20//! `ftui-core`, drives your `Model::update`, calls `Model::view` to render
21//! frames, and delegates rendering to `ftui-render` via `TerminalWriter`.
22//!
23//! # How it fits in the system
24//! The runtime is the center of the architecture: it is the bridge between
25//! input (`ftui-core`) and output (`ftui-render`). Widgets and layout are
26//! optional layers used by your `view()` to construct UI output.
27
28pub mod allocation_budget;
29pub mod asciicast;
30pub mod bocpd;
31pub mod conformal_alert;
32pub mod conformal_predictor;
33pub mod cost_model;
34pub mod debug_trace;
35pub mod diff_evidence;
36pub mod eprocess_throttle;
37pub mod evidence_bridges;
38pub mod evidence_sink;
39pub mod evidence_telemetry;
40pub mod flake_detector;
41pub mod input_fairness;
42pub mod input_macro;
43pub mod locale;
44pub mod log_sink;
45pub mod program;
46pub mod queueing_scheduler;
47#[cfg(feature = "render-thread")]
48pub mod render_thread;
49pub mod render_trace;
50pub mod resize_coalescer;
51pub mod resize_sla;
52pub mod simulator;
53pub mod state_persistence;
54#[cfg(feature = "stdio-capture")]
55pub mod stdio_capture;
56pub mod string_model;
57pub mod subscription;
58pub mod terminal_writer;
59pub mod undo;
60pub mod unified_evidence;
61pub mod validation_pipeline;
62pub mod voi_sampling;
63pub mod wasm_runner;
64
65pub mod reactive;
66pub mod schedule_trace;
67#[cfg(feature = "telemetry")]
68pub mod telemetry;
69pub mod voi_telemetry;
70
71pub use asciicast::{AsciicastRecorder, AsciicastWriter};
72pub use diff_evidence::{
73    DiffEvidenceLedger, DiffRegime, DiffStrategyRecord, Observation, RegimeTransition,
74};
75pub use evidence_sink::{EvidenceSink, EvidenceSinkConfig, EvidenceSinkDestination};
76pub use evidence_telemetry::{
77    BudgetDecisionSnapshot, ConformalSnapshot, DiffDecisionSnapshot, ResizeDecisionSnapshot,
78    budget_snapshot, clear_budget_snapshot, clear_diff_snapshot, clear_resize_snapshot,
79    diff_snapshot, resize_snapshot, set_budget_snapshot, set_diff_snapshot, set_resize_snapshot,
80};
81pub use ftui_backend::{BackendEventSource, BackendFeatures};
82#[cfg(feature = "native-backend")]
83pub use ftui_tty::TtyBackend;
84pub use input_macro::{
85    EventRecorder, FilteredEventRecorder, InputMacro, MacroPlayback, MacroPlayer, MacroRecorder,
86    RecordingFilter, RecordingState, TimedEvent,
87};
88pub use locale::{
89    Locale, LocaleContext, LocaleOverride, current_locale, detect_system_locale, set_locale,
90};
91pub use log_sink::LogSink;
92#[cfg(feature = "crossterm-compat")]
93pub use program::CrosstermEventSource;
94pub use program::{
95    App, AppBuilder, BatchController, Cmd, EffectQueueConfig, FrameTiming, FrameTimingConfig,
96    FrameTimingSink, HeadlessEventSource, InlineAutoRemeasureConfig, Model, MouseCapturePolicy,
97    PaneTerminalAdapter, PaneTerminalAdapterConfig, PaneTerminalDispatch,
98    PaneTerminalIgnoredReason, PaneTerminalLifecyclePhase, PaneTerminalLogEntry,
99    PaneTerminalLogOutcome, PaneTerminalSplitterHandle, PersistenceConfig, Program, ProgramConfig,
100    ResizeBehavior, TaskSpec, WidgetRefreshConfig, pane_terminal_resolve_splitter_target,
101    pane_terminal_splitter_handles, pane_terminal_target_from_hit,
102    register_pane_terminal_splitter_hits,
103};
104pub use render_trace::{
105    RenderTraceConfig, RenderTraceContext, RenderTraceFrame, RenderTraceRecorder,
106};
107pub use simulator::ProgramSimulator;
108pub use string_model::{StringModel, StringModelAdapter};
109pub use subscription::{Every, StopSignal, SubId, Subscription};
110pub use terminal_writer::{ScreenMode, TerminalWriter, UiAnchor, inline_active_widgets};
111pub use voi_telemetry::{
112    clear_inline_auto_voi_snapshot, inline_auto_voi_snapshot, set_inline_auto_voi_snapshot,
113};
114
115#[cfg(feature = "render-thread")]
116pub use render_thread::{OutMsg, RenderThread};
117
118#[cfg(feature = "stdio-capture")]
119pub use stdio_capture::{CapturedWriter, StdioCapture, StdioCaptureError};
120
121pub use allocation_budget::{
122    AllocationBudget, BudgetAlert, BudgetConfig, BudgetEvidence, BudgetSummary,
123};
124pub use conformal_alert::{
125    AlertConfig, AlertDecision, AlertEvidence, AlertReason, AlertStats, ConformalAlert,
126};
127pub use conformal_predictor::{
128    BucketKey, ConformalConfig, ConformalPrediction, ConformalPredictor, ConformalUpdate,
129    DiffBucket, ModeBucket,
130};
131pub use cost_model::{
132    BatchCostParams, BatchCostResult, CacheCostParams, CacheCostResult, PipelineCostParams,
133    PipelineCostResult, StageStats,
134};
135pub use eprocess_throttle::{
136    EProcessThrottle, ThrottleConfig, ThrottleDecision, ThrottleLog, ThrottleStats,
137};
138pub use flake_detector::{EvidenceLog, FlakeConfig, FlakeDecision, FlakeDetector, FlakeSummary};
139pub use reactive::{BatchScope, Binding, BindingScope, Computed, Observable, TwoWayBinding};
140pub use resize_coalescer::{
141    CoalesceAction, CoalescerConfig, CoalescerStats, CycleTimePercentiles, DecisionLog,
142    DecisionSummary, Regime, ResizeCoalescer,
143};
144pub use resize_sla::{
145    ResizeEvidence, ResizeSlaMonitor, SlaConfig, SlaLogEntry, SlaSummary, make_sla_hooks,
146};
147pub use undo::{
148    CommandBatch, CommandError, CommandMetadata, CommandResult, CommandSource, HistoryConfig,
149    HistoryManager, MergeConfig, TextDeleteCmd, TextInsertCmd, TextReplaceCmd, Transaction,
150    TransactionScope, UndoableCmd, WidgetId,
151};
152pub use unified_evidence::{
153    DecisionDomain, DomainSummary, EmitsEvidence, EvidenceEntry, EvidenceEntryBuilder,
154    EvidenceTerm, LedgerSummary, UnifiedEvidenceLedger,
155};
156pub use validation_pipeline::{
157    LedgerEntry, PipelineConfig, PipelineResult, PipelineSummary, ValidationOutcome,
158    ValidationPipeline, ValidatorStats,
159};
160pub use voi_sampling::{
161    VoiConfig, VoiDecision, VoiLogEntry, VoiObservation, VoiSampler, VoiSamplerSnapshot, VoiSummary,
162};
163
164// State persistence
165#[cfg(feature = "state-persistence")]
166pub use state_persistence::FileStorage;
167pub use state_persistence::{
168    MemoryStorage, RegistryStats, StateRegistry, StorageBackend, StorageError, StorageResult,
169    StoredEntry,
170};
171
172pub use schedule_trace::{
173    CancelReason, GoldenCompareResult, IsomorphismProof, ScheduleTrace, SchedulerPolicy, TaskEvent,
174    TraceConfig, TraceEntry, TraceSummary, WakeupReason, compare_golden,
175};
176
177// Diff strategy (re-exports from ftui-render)
178pub use ftui_render::diff_strategy::{
179    DiffStrategy, DiffStrategyConfig, DiffStrategySelector, StrategyEvidence,
180};
181pub use terminal_writer::RuntimeDiffConfig;
182pub use wasm_runner::{RenderedFrame, StepResult, WasmRunner};
183
184#[cfg(feature = "telemetry")]
185pub use telemetry::{
186    DecisionEvidence, EnabledReason, EndpointSource, EvidenceLedger, Protocol, SCHEMA_VERSION,
187    SpanId, TelemetryConfig, TelemetryError, TelemetryGuard, TraceContextSource, TraceId,
188    is_safe_env_var, redact,
189};