Skip to content

Commit e9dac1c

Browse files
committed
docstrings
1 parent 3716641 commit e9dac1c

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2424
- Added App.ALLOW_SELECT for a global switch to disable text selection https://github.com/Textualize/textual/pull/5409
2525
- Added `DOMNode.query_ancestor` https://github.com/Textualize/textual/pull/5409
2626
- Added selection to Log widget https://github.com/Textualize/textual/pull/5467
27+
- Added `text-wrap` and `text-overflow` CSS values https://github.com/Textualize/textual/pull/5485
28+
- Added Textual markup to replace Rich markup https://github.com/Textualize/textual/pull/5485
29+
- Added `Content.from_markup` https://github.com/Textualize/textual/pull/5485
2730

2831
### Fixed
2932

src/textual/content.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from __future__ import annotations
1111

1212
import re
13-
from functools import lru_cache, total_ordering
13+
from functools import cached_property, total_ordering
1414
from operator import itemgetter
1515
from typing import Callable, Iterable, NamedTuple, Sequence, Union
1616

@@ -137,7 +137,7 @@ def __init__(
137137
def __str__(self) -> str:
138138
return self._text
139139

140-
@property
140+
@cached_property
141141
def markup(self) -> str:
142142
"""Get Content markup to render this Text.
143143
@@ -260,7 +260,7 @@ def styled(
260260
style: Style | str = "",
261261
cell_length: int | None = None,
262262
) -> Content:
263-
"""Create a Content instance from a single styled piece of text.
263+
"""Create a Content instance from text and an optional style.
264264
265265
Args:
266266
text: String content.
@@ -294,9 +294,9 @@ def __lt__(self, other: object) -> bool:
294294
def is_same(self, content: Content) -> bool:
295295
"""Compare to another Content object.
296296
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).
300300
301301
Args:
302302
content: Content instance.
@@ -427,6 +427,19 @@ def render_strips(
427427
selection: Selection | None = None,
428428
selection_style: Style | None = None,
429429
) -> 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+
"""
430443
if not width:
431444
return []
432445

@@ -903,9 +916,9 @@ def render(
903916
yield end, base_style
904917
return
905918

919+
get_style: Callable[[str], Style]
906920
if parse_style is None:
907921

908-
@lru_cache(maxsize=1024)
909922
def get_style(style: str, /) -> Style:
910923
"""The default get_style method."""
911924
try:

src/textual/style.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from dataclasses import dataclass
1111
from functools import cached_property, lru_cache
1212
from marshal import dumps, loads
13-
from typing import TYPE_CHECKING, Any, Iterable
13+
from typing import TYPE_CHECKING, Any, Iterable, Mapping
1414

1515
import rich.repr
1616
from rich.style import Style as RichStyle
@@ -216,7 +216,7 @@ def parse(cls, text_style: str, variables: dict[str, str] | None = None) -> Styl
216216
variables: Optional mapping of CSS variables. `None` to get variables from the app.
217217
218218
Returns:
219-
_type_: _description_
219+
New style.
220220
"""
221221
from textual.markup import parse_style
222222

@@ -385,8 +385,8 @@ def combine(cls, styles: Iterable[Style]) -> Style:
385385
iter_styles = iter(styles)
386386
return sum(iter_styles, next(iter_styles))
387387

388-
@property
389-
def meta(self) -> dict[str, Any]:
388+
@cached_property
389+
def meta(self) -> Mapping[str, Any]:
390390
"""Get meta information (can not be changed after construction)."""
391391
return {} if self._meta is None else loads(self._meta)
392392

src/textual/visual.py

+2
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ def render_strips(
124124
width: Width of desired render.
125125
height: Height of desired render or `None` for any height.
126126
style: The base style to render on top of.
127+
selection: Selection information, if applicable, otherwise `None`.
128+
selection_style: Selection style if `selection` is not `None`.
127129
128130
Returns:
129131
An list of Strips.

0 commit comments

Comments
 (0)