Improve documentation and modernize type hints

This commit is contained in:
2026-04-01 21:06:34 -07:00
parent 5935140620
commit 32a8a1d4ad
6 changed files with 82 additions and 16 deletions

View File

@@ -14,18 +14,37 @@ from rp.pager import MousePager
@dataclass
class RenderOptions:
"""Rendering options for file display.
Attributes:
theme: Pygments color theme name.
line_numbers: Show line numbers. ``None`` enables them for code only.
pager: Use pager for output. ``None`` auto-detects terminal output.
"""
theme: str = "monokai"
line_numbers: bool | None = None
pager: bool | None = None
_MARKDOWN_TYPES = {"markdown", "md"}
_JSON_TYPES = {"json"}
_MARKDOWN_TYPES: set[str] = {"markdown", "md"}
_JSON_TYPES: set[str] = {"json"}
def render(
content: str, file_type: str, console: Console, options: RenderOptions
) -> None:
"""Render content to the console with syntax highlighting.
Renders Markdown with Rich Markdown, JSON with Rich JSON with a Syntax
fallback, and all other types with Pygments Syntax highlighting.
Args:
content: File content to render.
file_type: Pygments lexer name.
console: Rich console to render to.
options: Rendering options (theme, line numbers, pager).
"""
line_numbers = options.line_numbers
if line_numbers is None:
line_numbers = file_type not in _MARKDOWN_TYPES and file_type not in _JSON_TYPES