Skip to content

Conversation

@ZayanKhan-12
Copy link

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.

@Copilot Copilot AI review requested due to automatic review settings October 19, 2025 20:52
Copy link

Copilot AI left a 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-ansi CLI 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":
Copy link

Copilot AI Oct 19, 2025

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.

Copilot uses AI. Check for mistakes.
ZayanKhan-12 and others added 4 commits October 19, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant