Get a list of segments to render a pulse animation. Returns: List[Segment]: A list of segments, one segment per character.
(
self,
fore_style: Style,
back_style: Style,
color_system: str,
no_color: bool,
ascii: bool = False,
)
| 68 | |
| 69 | @lru_cache(maxsize=16) |
| 70 | def _get_pulse_segments( |
| 71 | self, |
| 72 | fore_style: Style, |
| 73 | back_style: Style, |
| 74 | color_system: str, |
| 75 | no_color: bool, |
| 76 | ascii: bool = False, |
| 77 | ) -> List[Segment]: |
| 78 | """Get a list of segments to render a pulse animation. |
| 79 | |
| 80 | Returns: |
| 81 | List[Segment]: A list of segments, one segment per character. |
| 82 | """ |
| 83 | bar = "-" if ascii else "━" |
| 84 | segments: List[Segment] = [] |
| 85 | if color_system not in ("standard", "eight_bit", "truecolor") or no_color: |
| 86 | segments += [Segment(bar, fore_style)] * (PULSE_SIZE // 2) |
| 87 | segments += [Segment(" " if no_color else bar, back_style)] * ( |
| 88 | PULSE_SIZE - (PULSE_SIZE // 2) |
| 89 | ) |
| 90 | return segments |
| 91 | |
| 92 | append = segments.append |
| 93 | fore_color = ( |
| 94 | fore_style.color.get_truecolor() |
| 95 | if fore_style.color |
| 96 | else ColorTriplet(255, 0, 255) |
| 97 | ) |
| 98 | back_color = ( |
| 99 | back_style.color.get_truecolor() |
| 100 | if back_style.color |
| 101 | else ColorTriplet(0, 0, 0) |
| 102 | ) |
| 103 | cos = math.cos |
| 104 | pi = math.pi |
| 105 | _Segment = Segment |
| 106 | _Style = Style |
| 107 | from_triplet = Color.from_triplet |
| 108 | |
| 109 | for index in range(PULSE_SIZE): |
| 110 | position = index / PULSE_SIZE |
| 111 | fade = 0.5 + cos(position * pi * 2) / 2.0 |
| 112 | color = blend_rgb(fore_color, back_color, cross_fade=fade) |
| 113 | append(_Segment(bar, _Style(color=from_triplet(color)))) |
| 114 | return segments |
| 115 | |
| 116 | def update(self, completed: float, total: Optional[float] = None) -> None: |
| 117 | """Update progress with new values. |