Skip to main content

trueno_gpu/monitor/tui_layout/
config.rs

1//! TUI configuration and section definitions.
2
3use super::widgets::Widget;
4
5// ============================================================================
6// TUI Configuration
7// ============================================================================
8
9/// TUI layout configuration
10#[derive(Debug, Clone)]
11pub struct TuiLayout {
12    /// Minimum terminal width
13    pub min_width: u16,
14    /// Minimum terminal height
15    pub min_height: u16,
16    /// Recommended terminal width
17    pub rec_width: u16,
18    /// Recommended terminal height
19    pub rec_height: u16,
20    /// Section definitions
21    pub sections: Vec<Section>,
22    /// Refresh rate in milliseconds
23    pub refresh_rate_ms: u64,
24    /// Number of sparkline data points
25    pub sparkline_points: usize,
26}
27
28impl Default for TuiLayout {
29    fn default() -> Self {
30        Self {
31            min_width: 80,
32            min_height: 24,
33            rec_width: 160,
34            rec_height: 48,
35            sections: vec![
36                Section::new("compute", "COMPUTE", 0.25),
37                Section::new("memory", "MEMORY", 0.20),
38                Section::new("dataflow", "DATA FLOW", 0.20),
39                Section::new("kernels", "KERNELS", 0.20),
40            ],
41            refresh_rate_ms: 100,
42            sparkline_points: 60,
43        }
44    }
45}
46
47impl TuiLayout {
48    /// Create a new TUI layout
49    #[must_use]
50    pub fn new() -> Self {
51        Self::default()
52    }
53
54    /// Set refresh rate
55    #[must_use]
56    pub fn with_refresh_rate(mut self, ms: u64) -> Self {
57        self.refresh_rate_ms = ms;
58        self
59    }
60
61    /// Check if terminal size meets minimum requirements
62    #[must_use]
63    pub fn check_size(&self, width: u16, height: u16) -> SizeCheck {
64        if width >= self.rec_width && height >= self.rec_height {
65            SizeCheck::Recommended
66        } else if width >= self.min_width && height >= self.min_height {
67            SizeCheck::Minimum
68        } else {
69            SizeCheck::TooSmall
70        }
71    }
72}
73
74/// Terminal size check result
75#[derive(Debug, Clone, Copy, PartialEq, Eq)]
76pub enum SizeCheck {
77    /// Terminal meets recommended size
78    Recommended,
79    /// Terminal meets minimum size
80    Minimum,
81    /// Terminal too small
82    TooSmall,
83}
84
85// ============================================================================
86// Section Definition
87// ============================================================================
88
89/// TUI section definition
90#[derive(Debug, Clone)]
91pub struct Section {
92    /// Section identifier
93    pub id: String,
94    /// Section title
95    pub title: String,
96    /// Height as percentage of total (0.0-1.0)
97    pub height_pct: f32,
98    /// Widgets in this section
99    pub widgets: Vec<Widget>,
100    /// Is section collapsed
101    pub collapsed: bool,
102    /// Is section focused
103    pub focused: bool,
104}
105
106impl Section {
107    /// Create a new section
108    #[must_use]
109    pub fn new(id: impl Into<String>, title: impl Into<String>, height_pct: f32) -> Self {
110        Self {
111            id: id.into(),
112            title: title.into(),
113            height_pct,
114            widgets: Vec::new(),
115            collapsed: false,
116            focused: false,
117        }
118    }
119
120    /// Add a widget to the section
121    pub fn add_widget(&mut self, widget: Widget) {
122        self.widgets.push(widget);
123    }
124
125    /// Toggle collapsed state
126    pub fn toggle_collapsed(&mut self) {
127        self.collapsed = !self.collapsed;
128    }
129}