1use colored::*;
2
3pub fn render_list(title: &str, headers: &[&str], rows: Vec<Vec<String>>, active_idx: Option<usize>) {
5 println!("{}", format!("=== {} ===", title).bold().bright_cyan());
7 println!("{}", "-".repeat(28));
8
9 let header_line = headers.join(" ");
11 println!("{}", header_line.bold());
12
13 println!("{}", "=".repeat(28));
14
15 let col_widths: Vec<usize> = (0..headers.len())
17 .map(|i| {
18 rows.iter()
19 .map(|r| r.get(i).map(|s| s.len()).unwrap_or(0))
20 .max()
21 .unwrap_or(0)
22 })
23 .collect();
24
25 for (i, row) in rows.iter().enumerate() {
27 let mut line = String::new();
28 for (j, cell) in row.iter().enumerate() {
29 let width = col_widths[j].max(headers[j].len());
30 let padded = format!("{:width$}", cell, width = width + 2);
31 line.push_str(&padded);
32 }
33 if Some(i) == active_idx {
34 println!("{}", line.bold().bright_yellow());
35 } else {
36 println!("{}", line);
37 }
38 println!(); }
40
41 println!("{}", "-".repeat(28));
42}