fusabi_tui/
lib.rs

1//! # Fusabi TUI
2//!
3//! A Terminal UI library providing Ratatui bindings and widgets for Fusabi scripts.
4//!
5//! ## Overview
6//!
7//! `fusabi-tui` enables Fusabi scripts to create rich terminal user interfaces by exposing
8//! Ratatui's powerful widget system and layout engine. This library provides:
9//!
10//! - **Widgets**: High-level UI components (lists, tables, charts, gauges, etc.)
11//! - **Layouts**: Flexbox-like constraint-based layout system
12//! - **Canvas**: Low-level drawing primitives for custom visualizations
13//! - **Bindings**: Native functions exposed to Fusabi scripts
14//!
15//! ## Architecture
16//!
17//! The library is organized into four main modules:
18//!
19//! - `widgets`: Ratatui widget wrappers and builders
20//! - `layouts`: Layout utilities and constraint handling
21//! - `canvas`: Canvas-based rendering for custom graphics
22//! - `bindings`: Fusabi VM integration and native function registration
23//!
24//! ## Example Usage
25//!
26//! ```fsharp
27//! // From a Fusabi script (.fsx)
28//! open Fusabi.TUI
29//!
30//! let list = List.create ["Item 1"; "Item 2"; "Item 3"]
31//! let layout = Layout.vertical [Constraint.Percentage 50; Constraint.Min 10]
32//! ```
33//!
34//! ## Features
35//!
36//! - Zero-copy where possible for performance
37//! - Type-safe widget construction
38//! - Composable layout system
39//! - Seamless Fusabi integration
40
41#[cfg(feature = "bindings")]
42pub mod bindings;
43pub mod canvas;
44pub mod formatting;
45pub mod layouts;
46pub mod widgets;
47
48// Re-export commonly used types for convenience
49#[cfg(feature = "bindings")]
50pub use bindings::FusabiTuiModule;
51pub use canvas::{GraphCanvas, GraphData, GraphEdge, GraphNode};
52pub use formatting::{format_bytes, format_duration, format_latency, format_number};
53pub use layouts::{Constraint, Layout};
54pub use widgets::table::{render_table, ColumnDef, TableData};
55pub use widgets::{Widget, WidgetBuilder};
56
57/// Result type alias for this crate
58pub type Result<T> = anyhow::Result<T>;
59
60/// Version of the fusabi-tui library
61pub const VERSION: &str = env!("CARGO_PKG_VERSION");
62
63#[cfg(test)]
64mod tests {
65    use super::*;
66
67    #[test]
68    fn test_version_constant() {
69        // VERSION is set at compile time from CARGO_PKG_VERSION
70        // We know it's valid if we get here (compile-time constant)
71        assert!(VERSION.starts_with("0."));
72    }
73}