Generate text from console contents (requires record=True argument in constructor). Args: clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``. styles (bool, optional): If ``True``, ansi escape codes will be included. ``False`` for plain
(self, *, clear: bool = True, styles: bool = False)
| 2190 | return result |
| 2191 | |
| 2192 | def export_text(self, *, clear: bool = True, styles: bool = False) -> str: |
| 2193 | """Generate text from console contents (requires record=True argument in constructor). |
| 2194 | |
| 2195 | Args: |
| 2196 | clear (bool, optional): Clear record buffer after exporting. Defaults to ``True``. |
| 2197 | styles (bool, optional): If ``True``, ansi escape codes will be included. ``False`` for plain text. |
| 2198 | Defaults to ``False``. |
| 2199 | |
| 2200 | Returns: |
| 2201 | str: String containing console contents. |
| 2202 | |
| 2203 | """ |
| 2204 | assert ( |
| 2205 | self.record |
| 2206 | ), "To export console contents set record=True in the constructor or instance" |
| 2207 | |
| 2208 | with self._record_buffer_lock: |
| 2209 | if styles: |
| 2210 | text = "".join( |
| 2211 | (style.render(text) if style else text) |
| 2212 | for text, style, _ in self._record_buffer |
| 2213 | ) |
| 2214 | else: |
| 2215 | text = "".join( |
| 2216 | segment.text |
| 2217 | for segment in self._record_buffer |
| 2218 | if not segment.control |
| 2219 | ) |
| 2220 | if clear: |
| 2221 | del self._record_buffer[:] |
| 2222 | return text |
| 2223 | |
| 2224 | def save_text( |
| 2225 | self, |