Files
trycua--cua/libs/python/cua-cli/cua_cli/utils/output.py
T
wehub-resource-sync 91e75e620b
CI: cua-driver distro-compat matrix / debian:12 (glibc 2.36) (push) Has been cancelled
CI: SPDX Headers / Check SPDX headers (warn-only) (push) Has been cancelled
CD: Docs MCP Server / build (linux/amd64) (push) Has been cancelled
CD: Docs MCP Server / build (linux/arm64) (push) Has been cancelled
CD: Docs MCP Server / merge (push) Has been cancelled
CI: cua-driver distro-compat matrix / Resolve release version (push) Has been cancelled
CI: cua-driver distro-compat matrix / fedora:41 (glibc 2.40) (push) Has been cancelled
CI: cua-driver distro-compat matrix / rockylinux:9 (glibc 2.34) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:22.04 (glibc 2.35) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:24.04 (glibc 2.39) (push) Has been cancelled
CI: cua-driver distro-compat matrix / Distro compat summary (push) Has been cancelled
CI: Rust Linux unit / Rust Linux unit and compile (push) Has been cancelled
CI: Rust Windows unit / Rust Windows unit and compile (push) Has been cancelled
CI: Nix Linux Rust source / Nix / compositor build (push) Has been cancelled
CI: Nix Linux Rust source / Nix / driver package (push) Has been cancelled
CI: Nix Linux Rust source / Nix / Rust unit tests (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:19 +08:00

67 lines
1.6 KiB
Python

"""Output formatting utilities for CUA CLI."""
import json
from typing import Any
from rich.console import Console
from rich.table import Table
console = Console()
error_console = Console(stderr=True)
def print_table(
data: list[dict[str, Any]],
columns: list[tuple[str, str]] | None = None,
title: str | None = None,
) -> None:
"""Print data as a formatted table.
Args:
data: List of dictionaries to display
columns: List of (key, header) tuples. If None, uses all keys from first item.
title: Optional table title
"""
if not data:
console.print("[dim]No data to display[/dim]")
return
table = Table(title=title, show_header=True, header_style="bold")
if columns is None:
columns = [(k, k.upper()) for k in data[0].keys()]
for _, header in columns:
table.add_column(header)
for item in data:
row = [str(item.get(key, "")) for key, _ in columns]
table.add_row(*row)
console.print(table)
def print_json(data: Any) -> None:
"""Print data as formatted JSON."""
console.print_json(json.dumps(data, indent=2, default=str))
def print_error(message: str) -> None:
"""Print an error message to stderr."""
error_console.print(f"[red]Error:[/red] {message}")
def print_success(message: str) -> None:
"""Print a success message."""
console.print(f"[green]{message}[/green]")
def print_warning(message: str) -> None:
"""Print a warning message."""
console.print(f"[yellow]Warning:[/yellow] {message}")
def print_info(message: str) -> None:
"""Print an info message."""
console.print(f"[blue]{message}[/blue]")