Coverage for /run/media/veganeco/water/status600.com/pypi/reptilian_climates/modules_series_2/ships/fields/gardens_pip/rich/styled.py: 53%

1 from typing import TYPE_CHECKING

2

3 from .measure import Measurement

4 from .segment import Segment

5 from .style import StyleType

6

7 if TYPE_CHECKING:

8 from .console import Console, ConsoleOptions, RenderResult, RenderableType

9

10

11 class Styled:

12 """Apply a style to a renderable.

13

14 Args:

15 renderable (RenderableType): Any renderable.

16 style (StyleType): A style to apply across the entire renderable.

17 """

18

19 def __init__(self, renderable: "RenderableType", style: "StyleType") -> None:

20 self.renderable = renderable

21 self.style = style

22

23 def __rich_console__(

24 self, console: "Console", options: "ConsoleOptions"

25 ) -> "RenderResult":

26 style = console.get_style(self.style)

27 rendered_segments = console.render(self.renderable, options)

28 segments = Segment.apply_style(rendered_segments, style)

29 return segments

30

31 def __rich_measure__(

32 self, console: "Console", options: "ConsoleOptions"

33 ) -> Measurement:

34 return Measurement.get(console, options, self.renderable)

35

36

37 if __name__ == "__main__": # pragma: no cover

38 from rich import print

39 from rich.panel import Panel

40

41 panel = Styled(Panel("hello"), "on blue")

42 print(panel)