Aluode/PerceptionLabPortable
0
1from typing import TYPE_CHECKING2 3from .measure import Measurement4from .segment import Segment5from .style import StyleType6 7if TYPE_CHECKING:8 from .console import Console, ConsoleOptions, RenderResult, RenderableType9 10 11class 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 = renderable21 self.style = style22 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 segments30 31 def __rich_measure__(32 self, console: "Console", options: "ConsoleOptions"33 ) -> Measurement:34 return Measurement.get(console, options, self.renderable)35 36 37if __name__ == "__main__": # pragma: no cover38 from pip._vendor.rich import print39 from pip._vendor.rich.panel import Panel40 41 panel = Styled(Panel("hello"), "on blue")42 print(panel)43 