Coverage for src/lilbee/runtime/console.py: 100%
18 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-09-28 17:20 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-09-28 17:20 +0000
1"""The Rich console lilbee prints through, which shows every string as literal text."""
3from __future__ import annotations
5from typing import IO, TYPE_CHECKING, TextIO
7from rich.console import Console, RenderableType
8from rich.highlighter import ReprHighlighter
9from rich.style import StyleType
10from rich.text import Text, TextType
12if TYPE_CHECKING:
13 from rich.status import Status
16class PlainConsole(Console):
17 """A Rich console that never parses a string as markup; style with ``Text`` or ``style=``."""
19 def __init__(
20 self,
21 *,
22 stderr: bool = False,
23 file: IO[str] | None = None,
24 force_terminal: bool | None = None,
25 width: int | None = None,
26 quiet: bool = False,
27 ) -> None:
28 super().__init__(
29 stderr=stderr,
30 file=file,
31 force_terminal=force_terminal,
32 width=width,
33 quiet=quiet,
34 markup=False,
35 )
37 def input(
38 self,
39 prompt: TextType = "",
40 *,
41 markup: bool = False,
42 emoji: bool = True,
43 password: bool = False,
44 stream: TextIO | None = None,
45 ) -> str:
46 """Read a line after showing *prompt* as literal text."""
47 return super().input(prompt, markup=markup, emoji=emoji, password=password, stream=stream)
49 def status(
50 self,
51 status: RenderableType,
52 *,
53 spinner: str = "dots",
54 spinner_style: StyleType = "status.spinner",
55 speed: float = 1.0,
56 refresh_per_second: float = 12.5,
57 ) -> Status:
58 """A spinner whose *status* string shows as literal text."""
59 return super().status(
60 Text(status) if isinstance(status, str) else status,
61 spinner=spinner,
62 spinner_style=spinner_style,
63 speed=speed,
64 refresh_per_second=refresh_per_second,
65 )
68def styled(*parts: str | tuple[str, StyleType]) -> Text:
69 """Literal text from ``(text, style)`` parts, highlighted the way a printed string is."""
70 assembled = Text.assemble(*parts)
71 highlighted = ReprHighlighter()(Text(assembled.plain))
72 highlighted.copy_styles(assembled)
73 return highlighted