Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/rich/screen.py: 38%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from typing import TYPE_CHECKING
3from ._loop import loop_last
4from .segment import Segment
5from .style import StyleType
7if TYPE_CHECKING:
8 from .console import Console, ConsoleOptions, RenderableType, RenderResult
11class Screen:
12 """A renderable that fills the terminal screen and crops excess.
14 Args:
15 renderable (RenderableType): Child renderable.
16 style (StyleType, optional): Optional background style. Defaults to None.
17 """
19 renderable: "RenderableType"
21 def __init__(
22 self,
23 *renderables: "RenderableType",
24 style: StyleType | None = None,
25 application_mode: bool = False,
26 ) -> None:
27 from rich.console import Group
29 self.renderable = Group(*renderables)
30 self.style = style
31 self.application_mode = application_mode
33 def __rich_console__(
34 self, console: "Console", options: "ConsoleOptions"
35 ) -> "RenderResult":
36 width, height = options.size
37 style = console.get_style(self.style) if self.style else None
38 render_options = options.update(width=width, height=height)
39 lines = console.render_lines(
40 self.renderable or "", render_options, style=style, pad=True
41 )
42 lines = Segment.set_shape(lines, width, height, style=style)
43 new_line = Segment("\n\r") if self.application_mode else Segment.line()
44 for last, line in loop_last(lines):
45 yield from line
46 if not last:
47 yield new_line