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