MCPcopy
hub / github.com/Textualize/rich / join

Method join

rich/text.py:778–815  ·  view source on GitHub ↗

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"])

Source from the content-addressed store, hash-verified

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.

Callers 15

from_ansiMethod · 0.95
check_textMethod · 0.95
make_tableFunction · 0.80
test_readFunction · 0.80
test_joinFunction · 0.80
test_save_svgFunction · 0.80
test_save_textFunction · 0.80
test_save_htmlFunction · 0.80
make_filename_textFunction · 0.80
downloadFunction · 0.80
snippets.pyFile · 0.80
__str__Method · 0.80

Calls 1

blank_copyMethod · 0.95

Tested by 6

make_tableFunction · 0.64
test_readFunction · 0.64
test_joinFunction · 0.64
test_save_svgFunction · 0.64
test_save_textFunction · 0.64
test_save_htmlFunction · 0.64