A context manager to *capture* the result of print() or log() in a string, rather than writing it to the console. Example: >>> from rich.console import Console >>> console = Console() >>> with console.capture() as capture: ... cons
(self)
| 1094 | self.control(Control.bell()) |
| 1095 | |
| 1096 | def capture(self) -> Capture: |
| 1097 | """A context manager to *capture* the result of print() or log() in a string, |
| 1098 | rather than writing it to the console. |
| 1099 | |
| 1100 | Example: |
| 1101 | >>> from rich.console import Console |
| 1102 | >>> console = Console() |
| 1103 | >>> with console.capture() as capture: |
| 1104 | ... console.print("[bold magenta]Hello World[/]") |
| 1105 | >>> print(capture.get()) |
| 1106 | |
| 1107 | Returns: |
| 1108 | Capture: Context manager with disables writing to the terminal. |
| 1109 | """ |
| 1110 | capture = Capture(self) |
| 1111 | return capture |
| 1112 | |
| 1113 | def pager( |
| 1114 | self, pager: Optional[Pager] = None, styles: bool = False, links: bool = False |