Join text together with this instance as the separator. Args: lines (Iterable[Text]): An iterable of Text instances to join. Returns: Text: A new text instance containing join text.
(self, lines: Iterable["Text"])
| 776 | yield _Segment(end) |
| 777 | |
| 778 | def join(self, lines: Iterable["Text"]) -> "Text": |
| 779 | """Join text together with this instance as the separator. |
| 780 | |
| 781 | Args: |
| 782 | lines (Iterable[Text]): An iterable of Text instances to join. |
| 783 | |
| 784 | Returns: |
| 785 | Text: A new text instance containing join text. |
| 786 | """ |
| 787 | |
| 788 | new_text = self.blank_copy() |
| 789 | |
| 790 | def iter_text() -> Iterable["Text"]: |
| 791 | if self.plain: |
| 792 | for last, line in loop_last(lines): |
| 793 | yield line |
| 794 | if not last: |
| 795 | yield self |
| 796 | else: |
| 797 | yield from lines |
| 798 | |
| 799 | extend_text = new_text._text.extend |
| 800 | append_span = new_text._spans.append |
| 801 | extend_spans = new_text._spans.extend |
| 802 | offset = 0 |
| 803 | _Span = Span |
| 804 | |
| 805 | for text in iter_text(): |
| 806 | extend_text(text._text) |
| 807 | if text.style: |
| 808 | append_span(_Span(offset, offset + len(text), text.style)) |
| 809 | extend_spans( |
| 810 | _Span(offset + start, offset + end, style) |
| 811 | for start, end, style in text._spans |
| 812 | ) |
| 813 | offset += len(text) |
| 814 | new_text._length = offset |
| 815 | return new_text |
| 816 | |
| 817 | def expand_tabs(self, tab_size: Optional[int] = None) -> None: |
| 818 | """Converts tabs to spaces. |