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

1"""Streaming display utilities for AI output.""" 

2 

3from __future__ import annotations 

4 

5from typing import TYPE_CHECKING 

6 

7from lintro.ai.providers.base import AIStreamResult 

8 

9if TYPE_CHECKING: 

10 from rich.console import Console 

11 

12 

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. 

20 

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. 

25 

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) 

35 

36 

37__all__ = ["stream_to_console"]