Skip to main content

presentar_terminal/
lib.rs

1//! Terminal backend for Presentar UI framework.
2#![allow(clippy::missing_const_for_fn)]
3#![allow(clippy::suboptimal_flops)]
4#![allow(clippy::cast_lossless)]
5// Style-only lints that don't affect correctness (SPEC-024 v5.8.0 quality compliance)
6#![allow(clippy::use_self)] // "unnecessary structure name repetition"
7#![allow(clippy::uninlined_format_args)] // "variables can be used directly in format!"
8#![allow(clippy::needless_range_loop)] // "loop variable only used to index"
9#![allow(clippy::bool_to_int_with_if)] // "unnecessary boolean not operation"
10#![allow(clippy::manual_map)] // "map_or can be simplified"
11#![allow(clippy::match_same_arms)] // "match arms have identical bodies" (intentional for readability)
12#![allow(clippy::explicit_iter_loop)] // "more concise to loop over references"
13#![allow(clippy::semicolon_if_nothing_returned)] // "consider adding semicolon"
14#![allow(clippy::format_collect)] // "use of format! to build string"
15#![allow(clippy::needless_pass_by_value)] // "argument passed by value but not consumed"
16#![allow(clippy::redundant_closure)] // "redundant closure"
17#![allow(clippy::struct_excessive_bools)] // "more than 3 bools in struct"
18#![allow(clippy::manual_clamp)] // "clamp-like pattern"
19#![allow(clippy::cast_possible_wrap)] // "casting may wrap around"
20#![allow(clippy::nonminimal_bool)] // "unnecessary boolean not operation"
21#![allow(clippy::option_map_or_none)] // "map_or can be simplified"
22#![allow(clippy::redundant_closure_for_method_calls)] // "redundant closure"
23#![allow(clippy::to_string_trait_impl)] // "calling to_string on &&str"
24#![allow(clippy::map_clone)] // "explicit closure for copying elements"
25#![allow(clippy::derivable_impls)] // "impl can be derived"
26#![allow(clippy::if_same_then_else)] // "if has identical blocks"
27#![allow(clippy::too_many_lines)] // "function has too many lines"
28#![allow(clippy::needless_borrow)] // "borrowed expression implements traits"
29#![allow(clippy::manual_str_repeat)] // "manual str::repeat"
30#![allow(clippy::unreadable_literal)] // "long literal lacking separators"
31#![allow(clippy::iter_cloned_collect)] // "implicitly cloning Vec"
32#![allow(clippy::or_fun_call)] // "function call inside map_or"
33#![allow(clippy::struct_field_names)] // "fields have same postfix"
34#![allow(clippy::items_after_statements)] // "adding items after statements"
35#![allow(clippy::collapsible_if)] // "all if blocks contain same code"
36#![allow(clippy::map_unwrap_or)] // "map().unwrap_or()"
37#![allow(clippy::implicit_clone)] // "implicitly cloning Vec"
38#![allow(clippy::doc_markdown)] // "item in documentation missing backticks"
39//!
40//! This crate bridges `presentar_core` abstractions (Canvas, Widget, Brick) to
41//! the terminal using `crossterm` directly.
42//!
43//! # Architecture (PROBAR-SPEC-009)
44//!
45//! The crate follows the Brick Architecture from PROBAR-SPEC-009:
46//!
47//! - All widgets implement `Brick` trait (tests define interface)
48//! - Jidoka gate prevents rendering if assertions fail
49//! - Performance budgets are enforced
50//! - Zero-allocation steady-state rendering via direct crossterm backend
51//!
52//! # Example
53//!
54//! ```ignore
55//! use presentar_terminal::{TuiApp, TuiConfig};
56//! use presentar_core::{Brick, Widget};
57//!
58//! // Create your root widget (must implement Widget + Brick)
59//! let root = MyRootWidget::new();
60//!
61//! // Run the application
62//! TuiApp::new(root)?.run()?;
63//! ```
64//!
65//! # Design Principles Enforcement
66//!
67//! This library enforces strict adherence to design principles (Tufte, Popper, Nielsen).
68//! The following `include_str!` ensures that the design principles test suite exists at compile time.
69#[cfg(test)]
70const _DESIGN_PRINCIPLES_TESTS: &str = include_str!("../tests/design_principles_interface.rs");
71
72mod app;
73pub mod cli;
74mod color;
75pub mod compute_block;
76pub mod direct;
77mod error;
78mod input;
79pub mod perf_trace;
80pub mod random_seed;
81pub mod seed;
82pub mod theme;
83pub mod tools;
84pub mod widgets;
85
86#[cfg(feature = "ptop")]
87pub mod ptop;
88
89// Re-export main types
90pub use app::{AsyncCollector, QaTimings, Snapshot, SnapshotReceiver, TuiApp, TuiConfig};
91pub use color::ColorMode;
92pub use direct::{Cell, CellBuffer, DiffRenderer, DirectTerminalCanvas, Modifiers};
93pub use error::TuiError;
94pub use input::{InputHandler, KeyBinding};
95pub use theme::{Gradient, Theme};
96
97// Re-export widget types
98pub use widgets::{
99    truncate,
100    // Data science widgets (sklearn/ggplot style)
101    Axis,
102    BarStyle,
103    BinStrategy,
104    // Legacy widgets (being phased out)
105    Border,
106    BorderStyle,
107    BoxPlot,
108    BoxStats,
109    BrailleGraph,
110    ColumnHighlight,
111    CompactBreakdown,
112    ConfusionMatrix,
113    CpuGrid,
114    Cursor,
115    CurveData,
116    CurveMode,
117    EmaConfig,
118    // UX utilities
119    EmptyState,
120    FocusRing,
121    ForceGraph,
122    ForceParams,
123    Gauge,
124    GaugeMode,
125    GraphEdge,
126    GraphMode,
127    GraphNode,
128    HealthStatus,
129    HeatBarStyle,
130    HeatScheme,
131    Heatmap,
132    HeatmapCell,
133    HeatmapPalette,
134    Histogram,
135    HistogramOrientation,
136    HorizonGraph,
137    HorizonScheme,
138    HugePages,
139    LegendPosition,
140    LineChart,
141    LineStyle,
142    LossCurve,
143    LossSeries,
144    MarkerStyle,
145    MatrixPalette,
146    MemoryBar,
147    MemorySegment,
148    Meter,
149    // Tufte-inspired data visualization widgets
150    MicroHeatBar,
151    MultiBarGraph,
152    MultiBarMode,
153    NetworkInterface,
154    NetworkPanel,
155    NodeId,
156    Normalization,
157    Orientation,
158    ProcessEntry,
159    ProcessSort,
160    ProcessState,
161    ProcessTable,
162    RocPrCurve,
163    // Tufte-inspired selection highlighting
164    RowHighlight,
165    ScatterAxis,
166    ScatterPlot,
167    Segment,
168    SegmentedMeter,
169    Series,
170    Simplification,
171    Sparkline,
172    Table,
173    TitleBar,
174    TitleBarPosition,
175    TitleBarStyle,
176    Tree,
177    TreeNode,
178    Treemap,
179    TreemapLayout,
180    TreemapNode,
181    TrendDirection,
182    ViolinData,
183    ViolinOrientation,
184    ViolinPlot,
185    ViolinStats,
186    DIMMED_BG,
187    SELECTION_ACCENT,
188    SELECTION_BG,
189    SELECTION_GUTTER,
190};
191
192// Re-export core types for convenience
193pub use presentar_core::{
194    Brick, BrickAssertion, BrickBudget, BrickVerification, Canvas, Color, Constraints, Point, Rect,
195    Size, TextStyle, Widget,
196};
197
198// Re-export random seed types (F1: Popper falsifiability)
199pub use random_seed::{
200    get_seed, init_from_env, set_global_seed, with_seed, SeededRng, DEFAULT_SEED,
201};
202
203// Re-export ComputeBlock types (SPEC-024 Section 15, 20)
204pub use compute_block::{
205    ComputeBlock, ComputeBlockId, CpuFrequencyBlock, CpuGovernor, CpuGovernorBlock,
206    FrequencyScalingState, GpuThermalBlock, GpuThermalState, GpuVramBlock, HugePagesBlock,
207    LoadTrendBlock, MemPressureBlock, MemoryPressureLevel, SimdInstructionSet, SparklineBlock,
208    TrendDirection as ComputeTrendDirection,
209};