Apply style(s) to an iterable of segments. Returns an iterable of segments where the style is replaced by ``style + segment.style + post_style``. Args: segments (Iterable[Segment]): Segments to process. style (Style, optional): Base style. Defaults to None.
(
cls,
segments: Iterable["Segment"],
style: Optional[Style] = None,
post_style: Optional[Style] = None,
)
| 185 | |
| 186 | @classmethod |
| 187 | def apply_style( |
| 188 | cls, |
| 189 | segments: Iterable["Segment"], |
| 190 | style: Optional[Style] = None, |
| 191 | post_style: Optional[Style] = None, |
| 192 | ) -> Iterable["Segment"]: |
| 193 | """Apply style(s) to an iterable of segments. |
| 194 | |
| 195 | Returns an iterable of segments where the style is replaced by ``style + segment.style + post_style``. |
| 196 | |
| 197 | Args: |
| 198 | segments (Iterable[Segment]): Segments to process. |
| 199 | style (Style, optional): Base style. Defaults to None. |
| 200 | post_style (Style, optional): Style to apply on top of segment style. Defaults to None. |
| 201 | |
| 202 | Returns: |
| 203 | Iterable[Segments]: A new iterable of segments (possibly the same iterable). |
| 204 | """ |
| 205 | result_segments = segments |
| 206 | if style: |
| 207 | apply = style.__add__ |
| 208 | result_segments = ( |
| 209 | cls(text, None if control else apply(_style), control) |
| 210 | for text, _style, control in result_segments |
| 211 | ) |
| 212 | if post_style: |
| 213 | result_segments = ( |
| 214 | cls( |
| 215 | text, |
| 216 | ( |
| 217 | None |
| 218 | if control |
| 219 | else (_style + post_style if _style else post_style) |
| 220 | ), |
| 221 | control, |
| 222 | ) |
| 223 | for text, _style, control in result_segments |
| 224 | ) |
| 225 | return result_segments |
| 226 | |
| 227 | @classmethod |
| 228 | def filter_control( |
no outgoing calls