|
10 | 10 | from __future__ import annotations
|
11 | 11 |
|
12 | 12 | import re
|
13 |
| -from functools import lru_cache, total_ordering |
| 13 | +from functools import cached_property, total_ordering |
14 | 14 | from operator import itemgetter
|
15 | 15 | from typing import Callable, Iterable, NamedTuple, Sequence, Union
|
16 | 16 |
|
@@ -137,7 +137,7 @@ def __init__(
|
137 | 137 | def __str__(self) -> str:
|
138 | 138 | return self._text
|
139 | 139 |
|
140 |
| - @property |
| 140 | + @cached_property |
141 | 141 | def markup(self) -> str:
|
142 | 142 | """Get Content markup to render this Text.
|
143 | 143 |
|
@@ -260,7 +260,7 @@ def styled(
|
260 | 260 | style: Style | str = "",
|
261 | 261 | cell_length: int | None = None,
|
262 | 262 | ) -> Content:
|
263 |
| - """Create a Content instance from a single styled piece of text. |
| 263 | + """Create a Content instance from text and an optional style. |
264 | 264 |
|
265 | 265 | Args:
|
266 | 266 | text: String content.
|
@@ -294,9 +294,9 @@ def __lt__(self, other: object) -> bool:
|
294 | 294 | def is_same(self, content: Content) -> bool:
|
295 | 295 | """Compare to another Content object.
|
296 | 296 |
|
297 |
| - Two Content objects are the same if their text and spans match. |
298 |
| - Note that if you use the `==` operator to compare Content instances, it will only consider the plain text portion of the content (and not the spans). |
299 |
| -
|
| 297 | + Two Content objects are the same if their text *and* spans match. |
| 298 | + Note that if you use the `==` operator to compare Content instances, it will only consider |
| 299 | + the plain text portion of the content (and not the spans). |
300 | 300 |
|
301 | 301 | Args:
|
302 | 302 | content: Content instance.
|
@@ -427,6 +427,19 @@ def render_strips(
|
427 | 427 | selection: Selection | None = None,
|
428 | 428 | selection_style: Style | None = None,
|
429 | 429 | ) -> list[Strip]:
|
| 430 | + """Render the visual into an iterable of strips. Part of the Visual protocol. |
| 431 | +
|
| 432 | + Args: |
| 433 | + rules: A mapping of style rules, such as the Widgets `styles` object. |
| 434 | + width: Width of desired render. |
| 435 | + height: Height of desired render or `None` for any height. |
| 436 | + style: The base style to render on top of. |
| 437 | + selection: Selection information, if applicable, otherwise `None`. |
| 438 | + selection_style: Selection style if `selection` is not `None`. |
| 439 | +
|
| 440 | + Returns: |
| 441 | + An list of Strips. |
| 442 | + """ |
430 | 443 | if not width:
|
431 | 444 | return []
|
432 | 445 |
|
@@ -903,9 +916,9 @@ def render(
|
903 | 916 | yield end, base_style
|
904 | 917 | return
|
905 | 918 |
|
| 919 | + get_style: Callable[[str], Style] |
906 | 920 | if parse_style is None:
|
907 | 921 |
|
908 |
| - @lru_cache(maxsize=1024) |
909 | 922 | def get_style(style: str, /) -> Style:
|
910 | 923 | """The default get_style method."""
|
911 | 924 | try:
|
|
0 commit comments