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
72#[macro_use]
73#[allow(unused_macros)]
74mod generated_contracts;
75
76mod app;
77pub mod cli;
78mod color;
79pub mod compute_block;
80pub mod direct;
81mod error;
82mod input;
83pub mod perf_trace;
84pub mod random_seed;
85pub mod seed;
86pub mod theme;
87pub mod tools;
88pub mod widgets;
89
90#[cfg(feature = "ptop")]
91pub mod ptop;
92
93// Re-export main types
94pub use app::{AsyncCollector, QaTimings, Snapshot, SnapshotReceiver, TuiApp, TuiConfig};
95pub use color::ColorMode;
96pub use direct::{Cell, CellBuffer, DiffRenderer, DirectTerminalCanvas, Modifiers};
97pub use error::TuiError;
98pub use input::{InputHandler, KeyBinding};
99pub use theme::{Gradient, Theme};
100
101// Re-export widget types
102pub use widgets::{
103    truncate,
104    // Data science widgets (sklearn/ggplot style)
105    Axis,
106    BarStyle,
107    BinStrategy,
108    // Legacy widgets (being phased out)
109    Border,
110    BorderStyle,
111    BoxPlot,
112    BoxStats,
113    BrailleGraph,
114    ColumnHighlight,
115    CompactBreakdown,
116    ConfusionMatrix,
117    CpuGrid,
118    Cursor,
119    CurveData,
120    CurveMode,
121    EmaConfig,
122    // UX utilities
123    EmptyState,
124    FocusRing,
125    ForceGraph,
126    ForceParams,
127    Gauge,
128    GaugeMode,
129    GraphEdge,
130    GraphMode,
131    GraphNode,
132    HealthStatus,
133    HeatBarStyle,
134    HeatScheme,
135    Heatmap,
136    HeatmapCell,
137    HeatmapPalette,
138    Histogram,
139    HistogramOrientation,
140    HorizonGraph,
141    HorizonScheme,
142    HugePages,
143    LegendPosition,
144    LineChart,
145    LineStyle,
146    LossCurve,
147    LossSeries,
148    MarkerStyle,
149    MatrixPalette,
150    MemoryBar,
151    MemorySegment,
152    Meter,
153    // Tufte-inspired data visualization widgets
154    MicroHeatBar,
155    MultiBarGraph,
156    MultiBarMode,
157    NetworkInterface,
158    NetworkPanel,
159    NodeId,
160    Normalization,
161    Orientation,
162    ProcessEntry,
163    ProcessSort,
164    ProcessState,
165    ProcessTable,
166    RocPrCurve,
167    // Tufte-inspired selection highlighting
168    RowHighlight,
169    ScatterAxis,
170    ScatterPlot,
171    Segment,
172    SegmentedMeter,
173    Series,
174    Simplification,
175    Sparkline,
176    Table,
177    TitleBar,
178    TitleBarPosition,
179    TitleBarStyle,
180    Tree,
181    TreeNode,
182    Treemap,
183    TreemapLayout,
184    TreemapNode,
185    TrendDirection,
186    ViolinData,
187    ViolinOrientation,
188    ViolinPlot,
189    ViolinStats,
190    DIMMED_BG,
191    SELECTION_ACCENT,
192    SELECTION_BG,
193    SELECTION_GUTTER,
194};
195
196// Re-export core types for convenience
197pub use presentar_core::{
198    Brick, BrickAssertion, BrickBudget, BrickVerification, Canvas, Color, Constraints, Point, Rect,
199    Size, TextStyle, Widget,
200};
201
202// Re-export random seed types (F1: Popper falsifiability)
203pub use random_seed::{
204    get_seed, init_from_env, set_global_seed, with_seed, SeededRng, DEFAULT_SEED,
205};
206
207// Re-export ComputeBlock types (SPEC-024 Section 15, 20)
208pub use compute_block::{
209    ComputeBlock, ComputeBlockId, CpuFrequencyBlock, CpuGovernor, CpuGovernorBlock,
210    FrequencyScalingState, GpuThermalBlock, GpuThermalState, GpuVramBlock, HugePagesBlock,
211    LoadTrendBlock, MemPressureBlock, MemoryPressureLevel, SimdInstructionSet, SparklineBlock,
212    TrendDirection as ComputeTrendDirection,
213};