-
Notifications
You must be signed in to change notification settings - Fork 95
Add --preprocess-ansi flag for HTML and SVG export #114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new --preprocess-ansi flag to Rich CLI that converts ANSI escape sequences into Rich renderables before exporting to HTML or SVG, ensuring colored console output renders correctly in exports.
- Adds
--preprocess-ansiCLI option to the main command - Implements ANSI preprocessing logic using AnsiDecoder and Group
- Refactors export handling to support optional ANSI preprocessing
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/rich_cli/main.py | Adds CLI flag and implements ANSI preprocessing functionality for HTML/SVG exports |
| tests/test_ansi_preprocessing.py | Comprehensive test suite covering ANSI preprocessing scenarios |
| test.sh | Script for running different test suites |
| test.patch | Placeholder file for test patches |
| setup-tests.sh | Setup script for test environment |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| from rich.ansi import AnsiDecoder | ||
| from rich.console import Group | ||
|
|
||
| def preprocess_ansi_text(text: str) -> "RenderableType": |
Copilot
AI
Oct 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function preprocess_ansi_text is defined but never used in the code. Consider removing it or integrating it into the export logic.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Summary
This pull request introduces a new CLI flag --preprocess-ansi that preprocesses ANSI escape sequences before exporting to HTML or SVG. This ensures colored console output, logs, and piped text containing ANSI codes render correctly when exported through Rich CLI.
Implementation details
Added --preprocess-ansi option to main() command in main.py.
Implemented preprocess_ansi_text() using AnsiDecoder and Group to safely convert ANSI sequences into Rich renderables.
Integrated preprocessing within the HTML/SVG export logic so that when --preprocess-ansi is used, text is decoded, re-rendered, and then exported.
Added a full test suite (tests/test_ansi_preprocessing.py) verifying:
SVG and HTML export correctness
Handling of piped ANSI input
Mixed ANSI and Rich markup rendering
Unicode, emoji, and special character safety
Testing
✅ All 9 new tests in tests/test_ansi_preprocessing.py pass:
pytest tests/test_ansi_preprocessing.py -v
====================== 9 passed in 0.05s ======================
Impact:
Improves the robustness of Rich CLI exports and allows users to convert ANSI-colored logs directly into styled HTML/SVG files.