Skip to main content

sentri_report/
formatter.rs

1//! Report formatting (JSON, Markdown, CLI).
2
3use super::Report;
4
5/// Formats reports in various output formats.
6pub struct ReportFormatter;
7
8impl ReportFormatter {
9    /// Format as JSON.
10    pub fn to_json(report: &Report) -> serde_json::Result<String> {
11        serde_json::to_string_pretty(&report)
12    }
13
14    /// Format as Markdown.
15    pub fn to_markdown(report: &Report) -> String {
16        format!(
17            "# {}\n\n**Generated:** {}\n**Program:** {}\n\n## Summary\n- Invariants Checked: {}\n- Violations: {}\n- Coverage: {}%\n",
18            report.title,
19            report.generated_at,
20            report.program,
21            report.invariants_checked,
22            report.violations_found,
23            report.coverage_percent
24        )
25    }
26
27    /// Format for CLI table.
28    pub fn to_cli_table(report: &Report) -> String {
29        format!(
30            "┌─────────────────────────────────────────┐\n│ {} (Coverage: {}%) │\n├─────────────────────────────────────────┤\n│ Invariants: {} | Violations: {} │\n└─────────────────────────────────────────┘\n",
31            report.program, report.coverage_percent, report.invariants_checked, report.violations_found
32        )
33    }
34}