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

Method split_cells

rich/segment.py:155–179  ·  view source on GitHub ↗

Split segment in to two segments at the specified column. If the cut point falls in the middle of a 2-cell wide character then it is replaced by two spaces, to preserve the display width of the parent segment. Args: cut (int): Offset within the segment to cut.

(self, cut: int)

Source from the content-addressed store, hash-verified

153 pos -= 1
154
155 def split_cells(self, cut: int) -> Tuple["Segment", "Segment"]:
156 """Split segment in to two segments at the specified column.
157
158 If the cut point falls in the middle of a 2-cell wide character then it is replaced
159 by two spaces, to preserve the display width of the parent segment.
160
161 Args:
162 cut (int): Offset within the segment to cut.
163
164 Returns:
165 Tuple[Segment, Segment]: Two segments.
166 """
167 text, style, control = self
168 assert cut >= 0
169
170 if _is_single_cell_widths(text):
171 # Fast path with all 1 cell characters
172 if cut >= len(text):
173 return self, Segment("", style, control)
174 return (
175 Segment(text[:cut], style, control),
176 Segment(text[cut:], style, control),
177 )
178
179 return self._split_cells(self, cut)
180
181 @classmethod
182 def line(cls) -> "Segment":

Callers 5

test_split_cells_emojiFunction · 0.80
test_split_cells_mixedFunction · 0.80
test_split_cells_doublesFunction · 0.80
test_split_cells_singleFunction · 0.80
divideMethod · 0.80

Calls 2

_split_cellsMethod · 0.95
SegmentClass · 0.85

Tested by 4

test_split_cells_emojiFunction · 0.64
test_split_cells_mixedFunction · 0.64
test_split_cells_doublesFunction · 0.64
test_split_cells_singleFunction · 0.64