Remove all color from an iterable of segments. Args: segments (Iterable[Segment]): An iterable segments. Yields: Segment: Segments with colorless style.
(cls, segments: Iterable["Segment"])
| 606 | |
| 607 | @classmethod |
| 608 | def remove_color(cls, segments: Iterable["Segment"]) -> Iterable["Segment"]: |
| 609 | """Remove all color from an iterable of segments. |
| 610 | |
| 611 | Args: |
| 612 | segments (Iterable[Segment]): An iterable segments. |
| 613 | |
| 614 | Yields: |
| 615 | Segment: Segments with colorless style. |
| 616 | """ |
| 617 | |
| 618 | cache: Dict[Style, Style] = {} |
| 619 | for text, style, control in segments: |
| 620 | if style: |
| 621 | colorless_style = cache.get(style) |
| 622 | if colorless_style is None: |
| 623 | colorless_style = style.without_color |
| 624 | cache[style] = colorless_style |
| 625 | yield cls(text, colorless_style, control) |
| 626 | else: |
| 627 | yield cls(text, None, control) |
| 628 | |
| 629 | @classmethod |
| 630 | def divide( |