Append iterable of str and style. Style may be a Style instance or a str style definition. Args: tokens (Iterable[Tuple[str, Optional[StyleType]]]): An iterable of tuples containing str content and style. Returns: Text: Returns self for chaining.
(
self, tokens: Iterable[Tuple[str, Optional[StyleType]]]
)
| 1028 | return self |
| 1029 | |
| 1030 | def append_tokens( |
| 1031 | self, tokens: Iterable[Tuple[str, Optional[StyleType]]] |
| 1032 | ) -> "Text": |
| 1033 | """Append iterable of str and style. Style may be a Style instance or a str style definition. |
| 1034 | |
| 1035 | Args: |
| 1036 | tokens (Iterable[Tuple[str, Optional[StyleType]]]): An iterable of tuples containing str content and style. |
| 1037 | |
| 1038 | Returns: |
| 1039 | Text: Returns self for chaining. |
| 1040 | """ |
| 1041 | append_text = self._text.append |
| 1042 | append_span = self._spans.append |
| 1043 | _Span = Span |
| 1044 | offset = len(self) |
| 1045 | for content, style in tokens: |
| 1046 | content = strip_control_codes(content) |
| 1047 | append_text(content) |
| 1048 | if style: |
| 1049 | append_span(_Span(offset, offset + len(content), style)) |
| 1050 | offset += len(content) |
| 1051 | self._length = offset |
| 1052 | return self |
| 1053 | |
| 1054 | def copy_styles(self, text: "Text") -> None: |
| 1055 | """Copy styles from another Text instance. |