MCPcopy
hub / github.com/Textualize/rich / export_text

Method export_text

rich/console.py:2192–2222  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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,

Callers 14

test_sectionFunction · 0.95
test_padding_widthFunction · 0.95
test_syntax_paddingFunction · 0.95
test_renderFunction · 0.95
test_printFunction · 0.95
test_export_textFunction · 0.95
test_capture_and_recordFunction · 0.95
test_ansi_in_pretty_reprFunction · 0.95

Calls 2

joinMethod · 0.80
renderMethod · 0.45

Tested by 12

test_sectionFunction · 0.76
test_padding_widthFunction · 0.76
test_syntax_paddingFunction · 0.76
test_renderFunction · 0.76
test_printFunction · 0.76
test_export_textFunction · 0.76
test_capture_and_recordFunction · 0.76
test_ansi_in_pretty_reprFunction · 0.76