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 decision_core;
36pub mod diff_evidence;
37pub mod eprocess_throttle;
38pub mod evidence_bridges;
39pub mod evidence_sink;
40pub mod evidence_telemetry;
41pub mod flake_detector;
42pub mod input_fairness;
43pub mod input_macro;
44pub mod locale;
45pub mod log_sink;
46pub mod program;
47pub mod queueing_scheduler;
48#[cfg(feature = "render-thread")]
49pub mod render_thread;
50pub mod render_trace;
51pub mod resize_coalescer;
52pub mod resize_sla;
53pub mod simulator;
54pub mod state_persistence;
55#[cfg(feature = "stdio-capture")]
56pub mod stdio_capture;
57pub mod string_model;
58pub mod subscription;
59pub mod terminal_writer;
60pub mod undo;
61pub mod unified_evidence;
62pub mod validation_pipeline;
63pub mod voi_sampling;
64pub mod wasm_runner;
65
66pub mod reactive;
67pub mod schedule_trace;
68#[cfg(feature = "telemetry")]
69pub mod telemetry;
70pub mod voi_telemetry;
71
72pub use asciicast::{AsciicastRecorder, AsciicastWriter};
73pub use diff_evidence::{
74    DiffEvidenceLedger, DiffRegime, DiffStrategyRecord, Observation, RegimeTransition,
75};
76pub use evidence_sink::{EvidenceSink, EvidenceSinkConfig, EvidenceSinkDestination};
77pub use evidence_telemetry::{
78    BudgetDecisionSnapshot, ConformalSnapshot, DiffDecisionSnapshot, ResizeDecisionSnapshot,
79    budget_snapshot, clear_budget_snapshot, clear_diff_snapshot, clear_resize_snapshot,
80    diff_snapshot, resize_snapshot, set_budget_snapshot, set_diff_snapshot, set_resize_snapshot,
81};
82pub use ftui_backend::{BackendEventSource, BackendFeatures};
83#[cfg(feature = "native-backend")]
84pub use ftui_tty::TtyBackend;
85pub use input_macro::{
86    EventRecorder, FilteredEventRecorder, InputMacro, MacroPlayback, MacroPlayer, MacroRecorder,
87    RecordingFilter, RecordingState, TimedEvent,
88};
89pub use locale::{
90    Locale, LocaleContext, LocaleOverride, current_locale, detect_system_locale, set_locale,
91};
92pub use log_sink::LogSink;
93#[cfg(feature = "crossterm-compat")]
94pub use program::CrosstermEventSource;
95pub use program::{
96    App, AppBuilder, BatchController, Cmd, EffectQueueConfig, FrameTiming, FrameTimingConfig,
97    FrameTimingSink, HeadlessEventSource, InlineAutoRemeasureConfig, Model, MouseCapturePolicy,
98    PaneTerminalAdapter, PaneTerminalAdapterConfig, PaneTerminalDispatch,
99    PaneTerminalIgnoredReason, PaneTerminalLifecyclePhase, PaneTerminalLogEntry,
100    PaneTerminalLogOutcome, PaneTerminalSplitterHandle, PersistenceConfig, Program, ProgramConfig,
101    ResizeBehavior, TaskSpec, WidgetRefreshConfig, pane_terminal_resolve_splitter_target,
102    pane_terminal_splitter_handles, pane_terminal_target_from_hit,
103    register_pane_terminal_splitter_hits,
104};
105pub use render_trace::{
106    RenderTraceConfig, RenderTraceContext, RenderTraceFrame, RenderTraceRecorder,
107};
108pub use simulator::ProgramSimulator;
109pub use string_model::{StringModel, StringModelAdapter};
110pub use subscription::{Every, StopSignal, SubId, Subscription};
111pub use terminal_writer::{ScreenMode, TerminalWriter, UiAnchor, inline_active_widgets};
112pub use voi_telemetry::{
113    clear_inline_auto_voi_snapshot, inline_auto_voi_snapshot, set_inline_auto_voi_snapshot,
114};
115
116#[cfg(feature = "render-thread")]
117pub use render_thread::{OutMsg, RenderThread};
118
119#[cfg(feature = "stdio-capture")]
120pub use stdio_capture::{CapturedWriter, StdioCapture, StdioCaptureError};
121
122pub use allocation_budget::{
123    AllocationBudget, BudgetAlert, BudgetConfig, BudgetEvidence, BudgetSummary,
124};
125pub use conformal_alert::{
126    AlertConfig, AlertDecision, AlertEvidence, AlertReason, AlertStats, ConformalAlert,
127};
128pub use conformal_predictor::{
129    BucketKey, ConformalConfig, ConformalPrediction, ConformalPredictor, ConformalUpdate,
130    DiffBucket, ModeBucket,
131};
132pub use cost_model::{
133    BatchCostParams, BatchCostResult, CacheCostParams, CacheCostResult, PipelineCostParams,
134    PipelineCostResult, StageStats,
135};
136pub use decision_core::{
137    Action as DecisionAction, Decision, DecisionCore, Outcome as DecisionOutcome, Posterior,
138    State as DecisionState, argmin_expected_loss, second_best_loss,
139};
140pub use eprocess_throttle::{
141    EProcessThrottle, ThrottleConfig, ThrottleDecision, ThrottleLog, ThrottleStats,
142};
143pub use flake_detector::{EvidenceLog, FlakeConfig, FlakeDecision, FlakeDetector, FlakeSummary};
144pub use reactive::{BatchScope, Binding, BindingScope, Computed, Observable, TwoWayBinding};
145pub use resize_coalescer::{
146    CoalesceAction, CoalescerConfig, CoalescerStats, CycleTimePercentiles, DecisionLog,
147    DecisionSummary, Regime, ResizeCoalescer,
148};
149pub use resize_sla::{
150    ResizeEvidence, ResizeSlaMonitor, SlaConfig, SlaLogEntry, SlaSummary, make_sla_hooks,
151};
152pub use undo::{
153    CommandBatch, CommandError, CommandMetadata, CommandResult, CommandSource, HistoryConfig,
154    HistoryManager, MergeConfig, TextDeleteCmd, TextInsertCmd, TextReplaceCmd, Transaction,
155    TransactionScope, UndoableCmd, WidgetId,
156};
157pub use unified_evidence::{
158    DecisionDomain, DomainSummary, EmitsEvidence, EvidenceEntry, EvidenceEntryBuilder,
159    EvidenceTerm, LedgerSummary, UnifiedEvidenceLedger,
160};
161pub use validation_pipeline::{
162    LedgerEntry, PipelineConfig, PipelineResult, PipelineSummary, ValidationOutcome,
163    ValidationPipeline, ValidatorStats,
164};
165pub use voi_sampling::{
166    VoiConfig, VoiDecision, VoiLogEntry, VoiObservation, VoiSampler, VoiSamplerSnapshot, VoiSummary,
167};
168
169// State persistence
170#[cfg(feature = "state-persistence")]
171pub use state_persistence::FileStorage;
172pub use state_persistence::{
173    MemoryStorage, RegistryStats, StateRegistry, StorageBackend, StorageError, StorageResult,
174    StoredEntry,
175};
176
177pub use schedule_trace::{
178    CancelReason, GoldenCompareResult, IsomorphismProof, ScheduleTrace, SchedulerPolicy, TaskEvent,
179    TraceConfig, TraceEntry, TraceSummary, WakeupReason, compare_golden,
180};
181
182// Diff strategy (re-exports from ftui-render)
183pub use ftui_render::diff_strategy::{
184    DiffStrategy, DiffStrategyConfig, DiffStrategySelector, StrategyEvidence,
185};
186pub use terminal_writer::RuntimeDiffConfig;
187pub use wasm_runner::{RenderedFrame, StepResult, WasmRunner};
188
189#[cfg(feature = "telemetry")]
190pub use telemetry::{
191    DecisionEvidence, EnabledReason, EndpointSource, EvidenceLedger, Protocol, SCHEMA_VERSION,
192    SpanId, TelemetryConfig, TelemetryError, TelemetryGuard, TraceContextSource, TraceId,
193    is_safe_env_var, redact,
194};