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

Method join

src/textual/content.py:931–990  ·  view source on GitHub ↗

Join an iterable of content or strings. This works much like the join method on `str` objects. Self is the separator (which maybe empty) placed between each string or Content. Args: lines: An iterable of other Content instances or or strings. Returns:

(self, lines: Iterable[Content | str])

Source from the content-addressed store, hash-verified

929 return self.append(Content.styled(text, style))
930
931 def join(self, lines: Iterable[Content | str]) -> Content:
932 """Join an iterable of content or strings.
933
934 This works much like the join method on `str` objects.
935 Self is the separator (which maybe empty) placed between each string or Content.
936
937 Args:
938 lines: An iterable of other Content instances or or strings.
939
940 Returns:
941 A single Content instance, containing all of the lines.
942
943 """
944 text: list[str] = []
945 spans: list[Span] = []
946
947 def iter_content() -> Iterable[Content]:
948 """Iterate the lines, optionally inserting the separator."""
949 if self.plain:
950 for last, line in loop_last(lines):
951 yield (
952 line
953 if isinstance(line, Content)
954 else Content(line, strip_control_codes=False)
955 )
956 if not last:
957 yield self
958 else:
959 for line in lines:
960 yield (
961 line
962 if isinstance(line, Content)
963 else Content(line, strip_control_codes=False)
964 )
965
966 extend_text = text.extend
967 extend_spans = spans.extend
968 offset = 0
969 _Span = Span
970
971 total_cell_length: int | None = self._cell_length
972
973 for content in iter_content():
974 if not content:
975 continue
976 extend_text(content._text)
977 extend_spans(
978 _Span(offset + start, offset + end, style)
979 for start, end, style in content._spans
980 if style
981 )
982 offset += len(content._text)
983 if total_cell_length is not None:
984 total_cell_length = (
985 None
986 if content._cell_length is None
987 else total_cell_length + content._cell_length
988 )

Callers 4

markupMethod · 0.45
assembleMethod · 0.45
appendMethod · 0.45
expand_tabsMethod · 0.45

Calls 2

_SpanClass · 0.85
ContentClass · 0.70

Tested by

no test coverage detected