Skip to main content

torvyn_cli/output/
table.rs

1//! Table rendering for structured data output.
2//!
3//! Uses the `tabled` crate for terminal table rendering.
4
5use crate::output::OutputContext;
6use tabled::{Table, Tabled};
7
8/// Render a table from a list of items to stderr.
9///
10/// COLD PATH — called by bench, inspect, doctor.
11#[allow(dead_code)]
12pub fn render_table<T: Tabled>(ctx: &OutputContext, items: &[T]) {
13    if items.is_empty() {
14        return;
15    }
16    let table = Table::new(items);
17    let table_str = table.to_string();
18
19    for line in table_str.lines() {
20        eprintln!("  {line}");
21    }
22    let _ = ctx;
23}
24
25/// Display an `Option<String>` for tabled rendering.
26fn display_option(o: &Option<String>) -> String {
27    o.clone().unwrap_or_default()
28}
29
30/// A single row in the doctor check output.
31#[derive(Debug, Tabled, serde::Serialize)]
32#[allow(dead_code)]
33pub struct DoctorCheckRow {
34    /// The check category or tool name.
35    #[tabled(rename = "Check")]
36    pub check: String,
37    /// Pass/fail status.
38    #[tabled(rename = "Status")]
39    pub status: String,
40    /// Detailed result or version info.
41    #[tabled(rename = "Detail")]
42    pub detail: String,
43    /// Fix suggestion if check failed.
44    #[tabled(rename = "Fix", display_with = "display_option")]
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub fix: Option<String>,
47}
48
49/// A row in the inspect interfaces table.
50#[derive(Debug, Tabled, serde::Serialize)]
51#[allow(dead_code)]
52pub struct InterfaceRow {
53    /// Direction (export/import).
54    #[tabled(rename = "Direction")]
55    pub direction: String,
56    /// Interface name.
57    #[tabled(rename = "Interface")]
58    pub interface: String,
59}