Add --preprocess-ansi flag for HTML and SVG export#114
Open
ZayanKhan-12 wants to merge 6 commits intoTextualize:mainfrom
Open
Add --preprocess-ansi flag for HTML and SVG export#114ZayanKhan-12 wants to merge 6 commits intoTextualize:mainfrom
ZayanKhan-12 wants to merge 6 commits intoTextualize:mainfrom
Conversation
There was a problem hiding this comment.
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": |
There was a problem hiding this comment.
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 <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.