| 1 |
|
| 2 |
|
| 3 |
use ratatui::Frame; |
| 4 |
use ratatui::layout::Constraint; |
| 5 |
use ratatui::style::{Color, Modifier, Style}; |
| 6 |
use ratatui::widgets::{Row, Table}; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
pub fn selected_style(i: usize, selected: Option<usize>) -> Style { |
| 11 |
if selected == Some(i) { |
| 12 |
Style::default() |
| 13 |
.bg(Color::DarkGray) |
| 14 |
.fg(Color::White) |
| 15 |
.add_modifier(Modifier::BOLD) |
| 16 |
} else { |
| 17 |
Style::default() |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
pub fn render_table( |
| 27 |
frame: &mut Frame, |
| 28 |
area: ratatui::layout::Rect, |
| 29 |
headers: &[&str], |
| 30 |
widths: &[Constraint], |
| 31 |
rows: Vec<Row>, |
| 32 |
) { |
| 33 |
let header = Row::new(headers.iter().map(|h| h.to_string()).collect::<Vec<_>>()) |
| 34 |
.style( |
| 35 |
Style::default() |
| 36 |
.fg(Color::DarkGray) |
| 37 |
.add_modifier(Modifier::BOLD), |
| 38 |
) |
| 39 |
.bottom_margin(0); |
| 40 |
|
| 41 |
let table = Table::new(rows, widths).header(header); |
| 42 |
frame.render_widget(table, area); |
| 43 |
} |
| 44 |
|