Skip to main content

hyprstream_tui/
console_app.rs

1//! ConsoleApp — floating log console backed by tui-logger.
2//!
3//! Holds mutable TuiWidgetState (scroll position, filters) and renders using
4//! TuiLoggerWidget. Lives in shell_handlers.rs, NOT in the compositor (which
5//! must remain WASM-safe).
6
7use hyprstream_compositor::theme;
8use ratatui::layout::Rect;
9use ratatui::prelude::Widget;
10use ratatui::style::{Color, Style};
11use ratatui::Frame;
12use tui_logger::{TuiLoggerWidget, TuiWidgetState};
13
14pub struct ConsoleApp {
15    pub state: TuiWidgetState,
16}
17
18impl ConsoleApp {
19    pub fn new() -> Self {
20        Self {
21            state: TuiWidgetState::new(),
22        }
23    }
24
25    /// Render the console content into `inner` (already inside the modal block frame).
26    pub fn draw(&mut self, frame: &mut Frame, inner: Rect) {
27        TuiLoggerWidget::default()
28            .style_error(Style::default().fg(Color::Red))
29            .style_warn(Style::default().fg(Color::Yellow))
30            .style_info(Style::default().fg(Color::White))
31            .style_debug(Style::default().fg(theme::DIM))
32            .output_timestamp(Some("%H:%M:%S".into()))
33            .output_target(true)
34            .output_file(false)
35            .output_line(false)
36            .state(&self.state)
37            .render(inner, frame.buffer_mut());
38    }
39}
40
41impl Default for ConsoleApp {
42    fn default() -> Self {
43        Self::new()
44    }
45}