A context manager to use a temporary theme. See :meth:`~rich.console.Console.use_theme` for usage.
| 341 | |
| 342 | |
| 343 | class ThemeContext: |
| 344 | """A context manager to use a temporary theme. See :meth:`~rich.console.Console.use_theme` for usage.""" |
| 345 | |
| 346 | def __init__(self, console: "Console", theme: Theme, inherit: bool = True) -> None: |
| 347 | self.console = console |
| 348 | self.theme = theme |
| 349 | self.inherit = inherit |
| 350 | |
| 351 | def __enter__(self) -> "ThemeContext": |
| 352 | self.console.push_theme(self.theme) |
| 353 | return self |
| 354 | |
| 355 | def __exit__( |
| 356 | self, |
| 357 | exc_type: Optional[Type[BaseException]], |
| 358 | exc_val: Optional[BaseException], |
| 359 | exc_tb: Optional[TracebackType], |
| 360 | ) -> None: |
| 361 | self.console.pop_theme() |
| 362 | |
| 363 | |
| 364 | class PagerContext: |