Coverage for lintro / ai / display / streaming.py: 0%
11 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-04-03 18:53 +0000
1"""Streaming display utilities for AI output."""
3from __future__ import annotations
5from typing import TYPE_CHECKING
7from lintro.ai.providers.base import AIStreamResult
9if TYPE_CHECKING:
10 from rich.console import Console
13def stream_to_console(
14 stream_result: AIStreamResult,
15 console: Console,
16 *,
17 style: str = "",
18) -> str:
19 """Stream AI tokens to a Rich console as they arrive.
21 Args:
22 stream_result: The streaming result to display.
23 console: Rich Console instance for output.
24 style: Optional Rich style string applied to each chunk.
26 Returns:
27 The full concatenated text that was streamed.
28 """
29 parts: list[str] = []
30 for chunk in stream_result:
31 console.print(chunk, end="", style=style or None, highlight=False, markup=False)
32 parts.append(chunk)
33 console.print()
34 return "".join(parts)
37__all__ = ["stream_to_console"]