all2md.cli.progress
Unified progress tracking and summary rendering for CLI.
This module provides abstractions for progress bars and summary tables that work with rich, tqdm, or plain text output, reducing code duplication across different processing modes.
- class all2md.cli.progress.ProgressContext
Bases:
objectUnified progress context for rich/tqdm/plain output.
This class provides a consistent interface for progress tracking across different output modes (rich terminal, tqdm, or plain text).
- Parameters:
use_rich (bool) – Whether to use Rich library for progress
use_progress (bool) – Whether to show progress at all (if False, uses plain output)
total (int) – Total number of items to process
description (str) – Description for progress bar
Examples
>>> with ProgressContext(use_rich=True, use_progress=True, total=10, description="Processing") as progress: ... for i in range(10): ... # Do work ... progress.update() ... progress.log(f"Processed item {i}", level='info')
Initialize progress context.
- __init__(use_rich: bool, use_progress: bool, total: int, description: str)
Initialize progress context.
- update(advance: int = 1) None
Update progress by advancing the specified amount.
- Parameters:
advance (int, default=1) – Number of items to advance
- log(message: str, level: str = 'info') None
Log a message (with color if using rich).
- Parameters:
message (str) – Message to log
level (str, default='info') – Log level: ‘info’, ‘success’, ‘warning’, ‘error’
- set_postfix(text: str) None
Set postfix text for progress bar (tqdm only).
- Parameters:
text (str) – Postfix text to display
- class all2md.cli.progress.SummaryRenderer
Bases:
objectRender summary tables in rich or plain text.
This class provides a consistent interface for rendering summary tables across different output modes.
- Parameters:
use_rich (bool) – Whether to use Rich library for table rendering
Examples
>>> renderer = SummaryRenderer(use_rich=True) >>> renderer.render_conversion_summary(successful=45, failed=5, total=50)
Initialize summary renderer.
- __init__(use_rich: bool)
Initialize summary renderer.
- render_conversion_summary(successful: int, failed: int, total: int, title: str = 'Conversion Summary') None
Render a conversion summary table.
- Parameters:
successful (int) – Number of successful conversions
failed (int) – Number of failed conversions
total (int) – Total number of files
title (str, default="Conversion Summary") – Table title
- render_two_column_table(rows: list[tuple[str, str]], title: str, col1_header: str = 'Item', col2_header: str = 'Status') None
Render a generic two-column table.
- Parameters:
rows (list[tuple[str, str]]) – List of (column1, column2) tuples
title (str) – Table title
col1_header (str, default="Item") – First column header
col2_header (str, default="Status") – Second column header
- all2md.cli.progress.create_progress_context_callback(progress: ProgressContext) Callable[[ProgressEvent], None]
Create a callback that feeds progress events into ProgressContext.
This wrapper translates progress events from parsers and retrievers into ProgressContext log messages, providing unified progress tracking across the CLI.
- Parameters:
progress (ProgressContext) – The progress context to feed events into
- Returns:
Callback function that handles progress events
- Return type:
Examples
>>> with ProgressContext(use_rich=True, use_progress=True, total=10, description="Processing") as progress: ... callback = create_progress_context_callback(progress) ... to_markdown("document.pdf", progress_callback=callback)