fur_cli/renderer/
list.rs

1use colored::*;
2
3/// Render a section header with rows aligned like a clean log.
4pub fn render_list(title: &str, headers: &[&str], rows: Vec<Vec<String>>, active_idx: Option<usize>) {
5    // Header
6    println!("{}", format!("=== {} ===", title).bold().bright_cyan());
7    println!("{}", "-".repeat(28));
8
9    // Column headers
10    let header_line = headers.join("    ");
11    println!("{}", header_line.bold());
12
13    println!("{}", "=".repeat(28));
14
15    // Compute column widths for alignment
16    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    // Print each row
26    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!(); // blank line for spacing
39    }
40
41    println!("{}", "-".repeat(28));
42}