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

Method split_lines_terminator

rich/segment.py:276–304  ·  view source on GitHub ↗

Split a sequence of segments in to a list of lines and a boolean to indicate if there was a new line. Args: segments (Iterable[Segment]): Segments potentially containing line feeds. Yields: Iterable[List[Segment]]: Iterable of segment lists, one per line.

(
        cls, segments: Iterable["Segment"]
    )

Source from the content-addressed store, hash-verified

274
275 @classmethod
276 def split_lines_terminator(
277 cls, segments: Iterable["Segment"]
278 ) -> Iterable[Tuple[List["Segment"], bool]]:
279 """Split a sequence of segments in to a list of lines and a boolean to indicate if there was a new line.
280
281 Args:
282 segments (Iterable[Segment]): Segments potentially containing line feeds.
283
284 Yields:
285 Iterable[List[Segment]]: Iterable of segment lists, one per line.
286 """
287 line: List[Segment] = []
288 append = line.append
289
290 for segment in segments:
291 if "\n" in segment.text and not segment.control:
292 text, style, _ = segment
293 while text:
294 _text, new_line, text = text.partition("\n")
295 if _text:
296 append(cls(_text, style))
297 if new_line:
298 yield (line, True)
299 line = []
300 append = line.append
301 else:
302 append(segment)
303 if line:
304 yield (line, False)
305
306 @classmethod
307 def split_and_crop_lines(

Callers 3

printMethod · 0.80

Calls

no outgoing calls