MCPcopy Create free account
hub / github.com/IBM/mcp-cli / StreamingDisplayManager

Class StreamingDisplayManager

src/mcp_cli/display/manager.py:58–768  ·  view source on GitHub ↗

Unified display manager for streaming responses. Uses Pydantic models for state and chuk-term for rendering. This is the ONLY display system - no fallback paths.

Source from the content-addressed store, hash-verified

56
57
58class StreamingDisplayManager:
59 """Unified display manager for streaming responses.
60
61 Uses Pydantic models for state and chuk-term for rendering.
62 This is the ONLY display system - no fallback paths.
63 """
64
65 def __init__(self, renderer: DisplayRenderer | None = None):
66 """Initialize display manager.
67
68 Args:
69 renderer: Custom renderer, defaults to ChukTermRenderer
70 """
71 self.renderer = renderer or ChukTermRenderer()
72
73 # Streaming state
74 self.streaming_state: StreamingState | None = None
75
76 # Tool execution state
77 self.tool_execution: "ToolExecutionState | None" = None
78
79 # Live status display for tool execution (handles terminal control properly)
80 # Uses chuk_term.ui.LiveStatus
81 self._tool_status: "LiveStatus | None" = None
82
83 # Background refresh task
84 self._refresh_task: asyncio.Task | None = None
85 self._refresh_active: bool = False
86
87 # Spinner animation
88 self._spinner_frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
89 self._spinner_index = 0
90
91 # Reasoning display debouncing
92 self._last_reasoning_update = 0.0
93 self._last_reasoning_chunk_count = 0
94 self._last_reasoning_preview = "" # Cached preview text
95 self._reasoning_update_interval = (
96 2.0 # seconds (increased for less frequent updates)
97 )
98 self._reasoning_chunk_interval = 20 # chunks (increased for less noise)
99
100 # Display state
101 self._last_status = ""
102 self._last_line_count = 0 # Track how many lines were last printed
103 self._showing_thinking = False # Track if we're showing thinking vs content
104
105 # Rendering lock to prevent simultaneous updates
106 self._render_lock = asyncio.Lock()
107
108 # ==================== STREAMING OPERATIONS ====================
109
110 async def start_streaming(self) -> None:
111 """Start a new streaming operation."""
112 if self.streaming_state and self.streaming_state.is_active:
113 logger.warning("Streaming already active, stopping previous stream")
114 await self.stop_streaming(interrupted=True)
115

Callers 7

__init__Method · 0.90
managerMethod · 0.90
managerMethod · 0.90

Calls

no outgoing calls

Tested by 6

managerMethod · 0.72
managerMethod · 0.72