Skip to content

Conversation

@ccmitchellusa
Copy link
Contributor

Summary

This PR fixes ANSI character handling and text wrapping issues in rich Panel displays throughout mcp-cli. The fixes ensure that:

  • ANSI escape sequences (colors, formatting) are preserved and displayed correctly
  • ASCII art and charts maintain proper structure without truncation
  • Regular text content wraps properly across multiple lines without ellipses
  • All panel types (Tool results, Streaming, Assistant) handle both content types consistently

Changes Made

Core Formatting (src/mcp_cli/tools/formatting.py)

  • Added format_content_with_ansi_support() helper function for consistent ANSI handling
  • Enhanced display_tool_call_result() to detect and properly format ANSI/ASCII content
  • Fixed text wrapping to use overflow="fold" instead of ellipses mode
  • Added zero-width space character cleaning for better display

Streaming Handler (src/mcp_cli/chat/streaming_handler.py)

  • Fixed ANSI content detection and handling in _create_display_content()
  • Resolved variable scope error that caused streaming failures
  • Applied consistent text wrapping approach for both ANSI and regular content

UI Manager (src/mcp_cli/chat/ui_manager.py)

  • Updated print_assistant_response() to handle ANSI content properly
  • Ensured fallback text rendering uses proper wrapping without ellipses

Command Tools (src/mcp_cli/commands/tools_call.py)

  • Fixed function signature bug in tool result display

Testing

  • Verified ANSI charts (from plotext_plus MCP server) display correctly with preserved colors
  • Confirmed long text content wraps across multiple lines without ellipses
  • Tested streaming functionality works without errors
  • Validated both vertical and horizontal orientations work properly

Technical Details

The key insight was distinguishing between content types:

  • ANSI/ASCII art: Uses Text.from_ansi() with no_wrap=True to preserve structure
  • Regular text: Uses Text() with overflow="fold", no_wrap=False for proper wrapping

Box-drawing characters are detected to identify ASCII art: {'┌', '┐', '└', '┘', '├', '┤', '┬', '┴', '┼', '│', '─', '█', '▄', '▀', '▌', '▐'}

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