Fix ANSI character handling in rich Panel displays #168
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 PR fixes ANSI character handling and text wrapping issues in rich Panel displays throughout mcp-cli. The fixes ensure that:
Changes Made
Core Formatting (
src/mcp_cli/tools/formatting.py)format_content_with_ansi_support()helper function for consistent ANSI handlingdisplay_tool_call_result()to detect and properly format ANSI/ASCII contentoverflow="fold"instead of ellipses modeStreaming Handler (
src/mcp_cli/chat/streaming_handler.py)_create_display_content()UI Manager (
src/mcp_cli/chat/ui_manager.py)print_assistant_response()to handle ANSI content properlyCommand Tools (
src/mcp_cli/commands/tools_call.py)Testing
Technical Details
The key insight was distinguishing between content types:
Text.from_ansi()withno_wrap=Trueto preserve structureText()withoverflow="fold", no_wrap=Falsefor proper wrappingBox-drawing characters are detected to identify ASCII art:
{'┌', '┐', '└', '┘', '├', '┤', '┬', '┴', '┼', '│', '─', '█', '▄', '▀', '▌', '▐'}