//! Shared TUI widget helpers to reduce table-rendering boilerplate. use ratatui::Frame; use ratatui::layout::Constraint; use ratatui::style::{Color, Modifier, Style}; use ratatui::widgets::{Row, Table}; /// Style for the currently selected row (DarkGray bg, White fg, Bold). /// Returns default style for non-selected rows. pub fn selected_style(i: usize, selected: Option) -> Style { if selected == Some(i) { Style::default() .bg(Color::DarkGray) .fg(Color::White) .add_modifier(Modifier::BOLD) } else { Style::default() } } /// Render a table with a styled header row. /// /// Callers build their own `Vec` (using [`selected_style`] for /// row highlighting) and pass column headers + widths. This function /// assembles the header, constructs the `Table`, and renders it. pub fn render_table( frame: &mut Frame, area: ratatui::layout::Rect, headers: &[&str], widths: &[Constraint], rows: Vec, ) { let header = Row::new(headers.iter().map(|h| h.to_string()).collect::>()) .style( Style::default() .fg(Color::DarkGray) .add_modifier(Modifier::BOLD), ) .bottom_margin(0); let table = Table::new(rows, widths).header(header); frame.render_widget(table, area); }