MCPcopy
hub / github.com/Textualize/textual / Content

Class Content

src/textual/content.py:133–1718  ·  view source on GitHub ↗

Text content with marked up spans. This object can be considered immutable, although it might update its internal state in a way that is consistent with immutability.

Source from the content-addressed store, hash-verified

131@rich.repr.auto
132@total_ordering
133class Content(Visual):
134 """Text content with marked up spans.
135
136 This object can be considered immutable, although it might update its internal state
137 in a way that is consistent with immutability.
138
139 """
140
141 __slots__ = ["_text", "_spans", "_cell_length"]
142
143 _NORMALIZE_TEXT_ALIGN = {"start": "left", "end": "right", "justify": "full"}
144
145 def __init__(
146 self,
147 text: str = "",
148 spans: list[Span] | None = None,
149 cell_length: int | None = None,
150 strip_control_codes: bool = True,
151 ) -> None:
152 """
153 Initialize a Content object.
154
155 Args:
156 text: text content.
157 spans: Optional list of spans.
158 cell_length: Cell length of text if known, otherwise `None`.
159 strip_control_codes: Strip control codes that may break output?
160 """
161
162 self._text: str = (
163 _strip_control_codes(text) if strip_control_codes and text else text
164 )
165 self._spans: list[Span] = [] if spans is None else spans
166 self._cell_length = cell_length
167 self._optimal_width_cache: int | None = None
168 self._minimal_width_cache: int | None = None
169 self._height_cache: tuple[tuple[int, str, bool] | None, int] = (None, 0)
170 self._divide_cache: (
171 FIFOCache[Sequence[int], list[tuple[Span, int, int]]] | None
172 ) = None
173 self._split_cache: FIFOCache[tuple[str, bool, bool], list[Content]] | None = (
174 None
175 )
176 # If there are 1 or 0 spans, it can't be simplified further
177 self._simplified = len(self._spans) <= 1
178
179 def __str__(self) -> str:
180 return self._text
181
182 @property
183 def _is_regular(self) -> bool:
184 """Check if the line is regular (spans.end > span.start for all spans).
185
186 This is a debugging aid, and unlikely to be useful in your app.
187
188 Returns:
189 `True` if the content is regular, `False` if it is not (and broken).
190 """

Callers 15

highlightFunction · 0.90
_gather_commandsMethod · 0.90
visualizeFunction · 0.90
format_titleMethod · 0.90
_to_contentFunction · 0.90
CollapsibleTitleClass · 0.90
renderMethod · 0.90
__init__Method · 0.90
_token_to_contentMethod · 0.90
renderMethod · 0.90

Calls

no outgoing calls

Tested by 15

test_render_strFunction · 0.72
test_blankFunction · 0.72
test_simpleFunction · 0.72
test_constructorFunction · 0.72
test_boolFunction · 0.72
test_getitemFunction · 0.72
test_cell_lengthFunction · 0.72
test_stylizeFunction · 0.72
test_stylize_beforeFunction · 0.72
test_eqFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…