code_mesh_tui/
renderer.rs

1use ratatui::{
2    Frame,
3    layout::Rect,
4    widgets::Widget,
5};
6
7use crate::theme::Theme;
8
9/// Renderer wrapper for consistent styling and theme application
10pub struct Renderer<'a> {
11    frame: &'a mut Frame<'a>,
12    theme: &'a dyn Theme,
13}
14
15impl<'a> Renderer<'a> {
16    /// Create a new renderer
17    pub fn new(frame: &'a mut Frame<'a>, theme: &'a dyn Theme) -> Self {
18        Self { frame, theme }
19    }
20    
21    /// Get the current theme
22    pub fn theme(&self) -> &dyn Theme {
23        self.theme
24    }
25    
26    /// Render a widget in the specified area
27    pub fn render_widget<W: Widget>(&mut self, widget: W, area: Rect) {
28        self.frame.render_widget(widget, area);
29    }
30    
31    /// Render a stateful widget
32    pub fn render_stateful_widget<W: ratatui::widgets::StatefulWidget>(
33        &mut self, 
34        widget: W, 
35        area: Rect, 
36        state: &mut W::State
37    ) {
38        self.frame.render_stateful_widget(widget, area, state);
39    }
40    
41    /// Get the terminal size
42    pub fn size(&self) -> Rect {
43        self.frame.size()
44    }
45}