From 9d1ab5859a56c73f2673e8bc05e3c2691d138d77 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Tue, 3 Feb 2026 06:56:41 +0000 Subject: [PATCH] Add CLI commands and output renderer --- vibeguard/cli/output/renderer.py | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 vibeguard/cli/output/renderer.py diff --git a/vibeguard/cli/output/renderer.py b/vibeguard/cli/output/renderer.py new file mode 100644 index 0000000..fcf05f5 --- /dev/null +++ b/vibeguard/cli/output/renderer.py @@ -0,0 +1,68 @@ +"""Output rendering for VibeGuard CLI.""" + +from typing import Any + +from rich.console import Console +from rich.panel import Panel +from rich.table import Table +from rich.text import Text + +from vibeguard.cli.theme import VibeGuardTheme + + +class OutputRenderer: + """Render VibeGuard output using Rich.""" + + def __init__(self, console: Console | None = None) -> None: + self.console = console or Console(theme=VibeGuardTheme.get_theme()) + + def render_issue(self, issue: dict[str, Any]) -> None: + """Render a single issue to the console.""" + severity = issue.get("severity", "info") + pattern = issue.get("pattern", "Unknown") + file = issue.get("file", "Unknown") + line = issue.get("line", 0) + message = issue.get("message", "") + suggestion = issue.get("suggestion", "") + + content = Text() + content.append(f"[{pattern}]\n", style="pattern") + content.append(f"File: {file}:{line}\n", style="file") + content.append(f"{message}\n\n", style=severity) + + if suggestion: + content.append("Fix: ", style="bold") + content.append(f"{suggestion}\n", style="success") + + panel = Panel(content, title=f"[{severity}]{pattern}[/{severity}]") + self.console.print(panel) + + def render_summary(self, issues: list[dict[str, Any]]) -> None: + """Render summary of analysis results.""" + severity_counts = {"critical": 0, "error": 0, "warning": 0, "info": 0} + + for issue in issues: + severity = issue.get("severity", "info") + severity_counts[severity] = severity_counts.get(severity, 0) + 1 + + table = Table(title="Analysis Summary") + table.add_column("Severity", style="bold") + table.add_column("Count", justify="right") + + for severity in ["critical", "error", "warning", "info"]: + count = severity_counts.get(severity, 0) + style = severity if severity != "warning" else "warning" + table.add_row(f"[{style}]{severity.upper()}[/{style}]", str(count)) + + self.console.print(table) + + def render_statistics(self, stats: dict[str, Any]) -> None: + """Render analysis statistics.""" + table = Table(title="Statistics") + table.add_column("Metric") + table.add_column("Value", justify="right") + + for key, value in stats.items(): + table.add_row(key.replace("_", " ").title(), str(value)) + + self.console.print(table)