Skip to content

rich_formatter

appimage_updater.ui.output.rich_formatter

Rich console output formatter implementation.

RichOutputFormatter(console=None, verbose=False, **kwargs)

Rich console output formatter.

This formatter provides the existing Rich console behavior, maintaining backward compatibility while implementing the OutputFormatter protocol.

Parameters:

Name Type Description Default
console Console | None

Optional Rich console instance. Creates default if not provided.

None
verbose bool

Enable verbose output (currently unused but accepted for compatibility)

False
**kwargs Any

Additional arguments (ignored for compatibility)

{}
Source code in src/appimage_updater/ui/output/rich_formatter.py
def __init__(self, console: Console | None = None, verbose: bool = False, **kwargs: Any):
    """Initialize the Rich formatter.

    Args:
        console: Optional Rich console instance. Creates default if not provided.
        verbose: Enable verbose output (currently unused but accepted for compatibility)
        **kwargs: Additional arguments (ignored for compatibility)
    """
    self.console = console or Console(no_color=bool(os.environ.get("NO_COLOR")))
    self._current_section: str | None = None
    self.verbose = verbose

console = console or Console(no_color=(bool(os.environ.get('NO_COLOR')))) instance-attribute

verbose = verbose instance-attribute

end_section()

End the current output section.

Source code in src/appimage_updater/ui/output/rich_formatter.py
def end_section(self) -> None:
    """End the current output section."""
    if self._current_section:
        self.console.print("")  # Add spacing
        self._current_section = None

finalize()

Finalize Rich output.

Rich output goes directly to console, so this returns None.

Returns:

Type Description
str | None

None for console output

Source code in src/appimage_updater/ui/output/rich_formatter.py
def finalize(self) -> str | None:
    """Finalize Rich output.

    Rich output goes directly to console, so this returns None.

    Returns:
        None for console output
    """
    return None

print(message, **kwargs)

Print a message with Rich styling.

Parameters:

Name Type Description Default
message str

The message to print

required
**kwargs Any

Rich console print options (style, highlight, etc.)

{}
Source code in src/appimage_updater/ui/output/rich_formatter.py
def print(self, message: str, **kwargs: Any) -> None:
    """Print a message with Rich styling.

    Args:
        message: The message to print
        **kwargs: Rich console print options (style, highlight, etc.)
    """
    self.console.print(message, **kwargs)

print_application_list(applications)

Display application list using Rich table.

Parameters:

Name Type Description Default
applications list[dict[str, Any]]

List of application dictionaries

required
Source code in src/appimage_updater/ui/output/rich_formatter.py
def print_application_list(self, applications: list[dict[str, Any]]) -> None:
    """Display application list using Rich table.

    Args:
        applications: List of application dictionaries
    """
    table = Table(title="Configured Applications")
    table.add_column("Application", style="cyan", no_wrap=False)
    table.add_column("Status", style="green")
    table.add_column("Source", style="yellow", no_wrap=False, overflow="fold")
    table.add_column("Download Directory", style="magenta", no_wrap=False)

    for app in applications:
        # Handle dict format as specified by interface
        name = app.get("name", "")
        status = "Enabled" if app.get("enabled", True) else "Disabled"

        # Format source - let table handle wrapping with overflow='fold'
        url = app.get("url", "")
        source_display = url

        # Wrap download directory path - increased width to show parent directory
        download_dir = self._wrap_path(app.get("download_dir", ""), 30)

        table.add_row(name, status, source_display, download_dir)

    self.console.print(table)

print_check_results(results)

Display check results using Rich table formatting.

Parameters:

Name Type Description Default
results list[dict[str, Any]]

List of check result dictionaries

required
Source code in src/appimage_updater/ui/output/rich_formatter.py
def print_check_results(self, results: list[dict[str, Any]]) -> None:
    """Display check results using Rich table formatting.

    Args:
        results: List of check result dictionaries
    """
    # Convert to CheckResult objects for display
    check_results: list[CheckResult] = []
    for result_data in results:
        # Create CheckResult from dict
        check_results.append(self._dict_to_check_result(result_data))

    self._display_check_results_table(check_results)

print_config_settings(settings)

Display configuration settings.

Parameters:

Name Type Description Default
settings dict[str, Any]

Dictionary of configuration settings

required
Source code in src/appimage_updater/ui/output/rich_formatter.py
def print_config_settings(self, settings: dict[str, Any]) -> None:
    """Display configuration settings.

    Args:
        settings: Dictionary of configuration settings
    """
    table = Table(title="Configuration Settings")
    table.add_column("Setting", style="cyan")
    table.add_column("Value", style="green")

    for key, value in settings.items():
        table.add_row(key, str(value))

    self.console.print(table)

print_error(message)

Display error message with red styling.

Parameters:

Name Type Description Default
message str

Error message to display

required
Source code in src/appimage_updater/ui/output/rich_formatter.py
def print_error(self, message: str) -> None:
    """Display error message with red styling.

    Args:
        message: Error message to display
    """
    self.console.print(f"[red]{message}[/red]")

print_info(message)

Display info message with blue styling.

Parameters:

Name Type Description Default
message str

Info message to display

required
Source code in src/appimage_updater/ui/output/rich_formatter.py
def print_info(self, message: str) -> None:
    """Display info message with blue styling.

    Args:
        message: Info message to display
    """
    self.console.print(f"[blue]{message}[/blue]")

print_progress(current, total, description='')

Display progress information.

Parameters:

Name Type Description Default
current int

Current progress value

required
total int

Total progress value

required
description str

Optional progress description

''
Source code in src/appimage_updater/ui/output/rich_formatter.py
def print_progress(self, current: int, total: int, description: str = "") -> None:
    """Display progress information.

    Args:
        current: Current progress value
        total: Total progress value
        description: Optional progress description
    """
    percentage = (current / total * 100) if total > 0 else 0
    progress_text = f"[{current}/{total}] ({percentage:.1f}%)"
    if description:
        progress_text = f"{description}: {progress_text}"

    self.console.print(progress_text)

print_success(message)

Display success message with green styling.

Parameters:

Name Type Description Default
message str

Success message to display

required
Source code in src/appimage_updater/ui/output/rich_formatter.py
def print_success(self, message: str) -> None:
    """Display success message with green styling.

    Args:
        message: Success message to display
    """
    self.console.print(f"[green]{message}[/green]")

print_table(data, title='', headers=None)

Display tabular data using Rich Table.

Parameters:

Name Type Description Default
data list[dict[str, Any]]

List of dictionaries representing table rows

required
title str

Optional table title

''
headers list[str] | None

Optional custom headers (uses dict keys if not provided)

None
Source code in src/appimage_updater/ui/output/rich_formatter.py
def print_table(self, data: list[dict[str, Any]], title: str = "", headers: list[str] | None = None) -> None:
    """Display tabular data using Rich Table.

    Args:
        data: List of dictionaries representing table rows
        title: Optional table title
        headers: Optional custom headers (uses dict keys if not provided)
    """
    if not data:
        return

    # Create and configure table
    table = self._create_rich_table(title)
    table_headers = self._determine_table_headers(data, headers)

    # Build table structure
    self._add_table_columns(table, table_headers)
    self._add_table_rows(table, data, table_headers)

    # Display table
    self.console.print(table)

print_warning(message)

Display warning message with yellow styling.

Parameters:

Name Type Description Default
message str

Warning message to display

required
Source code in src/appimage_updater/ui/output/rich_formatter.py
def print_warning(self, message: str) -> None:
    """Display warning message with yellow styling.

    Args:
        message: Warning message to display
    """
    self.console.print(f"[yellow]{message}[/yellow]")

start_section(title)

Start a new output section with Rich panel.

Parameters:

Name Type Description Default
title str

Section title

required
Source code in src/appimage_updater/ui/output/rich_formatter.py
def start_section(self, title: str) -> None:
    """Start a new output section with Rich panel.

    Args:
        title: Section title
    """
    self._current_section = title
    self.console.print(f"\n[bold cyan]{title}[/bold cyan]")
    self.console.print("=" * len(title))