Apply a style to the text, or a portion of the text. Args: style (Union[str, Style]): Style instance or style definition to apply. start (int): Start offset (negative indexing is supported). Defaults to 0. end (Optional[int], optional): End offset (negati
(
self,
style: Union[str, Style],
start: int = 0,
end: Optional[int] = None,
)
| 455 | return copy_self |
| 456 | |
| 457 | def stylize( |
| 458 | self, |
| 459 | style: Union[str, Style], |
| 460 | start: int = 0, |
| 461 | end: Optional[int] = None, |
| 462 | ) -> None: |
| 463 | """Apply a style to the text, or a portion of the text. |
| 464 | |
| 465 | Args: |
| 466 | style (Union[str, Style]): Style instance or style definition to apply. |
| 467 | start (int): Start offset (negative indexing is supported). Defaults to 0. |
| 468 | end (Optional[int], optional): End offset (negative indexing is supported), or None for end of text. Defaults to None. |
| 469 | """ |
| 470 | if style: |
| 471 | length = len(self) |
| 472 | if start < 0: |
| 473 | start = length + start |
| 474 | if end is None: |
| 475 | end = length |
| 476 | if end < 0: |
| 477 | end = length + end |
| 478 | if start >= length or end <= start: |
| 479 | # Span not in text or not valid |
| 480 | return |
| 481 | self._spans.append(Span(start, min(length, end), style)) |
| 482 | |
| 483 | def stylize_before( |
| 484 | self, |