Skip to content

Commit 37cc1b9

Browse files
shrimblyclaude
andcommitted
drive title shimmer from one interval timer
Per-frame one-shot timers whose deadlines sit closer together than the platform timer resolution fire out of order on Windows, which could end the shimmer pass on a highlighted frame instead of the original title. A single interval timer advances the frame index, making the order and final frame structural. The completion test now asserts the exact frame sequence. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent c2a4e70 commit 37cc1b9

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

‎sharp_frames/ui/screens/configuration.py‎

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
Removes selection method configuration (moved to post-extraction SelectionScreen).
44
"""
55

6-
from functools import partial
7-
86
from rich.text import Text
97
from textual.app import ComposeResult
108
from textual.containers import Container, Horizontal
@@ -132,13 +130,34 @@ def on_mount(self) -> None:
132130
if self.app.animation_level == "none":
133131
return
134132

135-
for frame_index in range(1, len(self.frames)):
136-
self.set_timer(
137-
self.INITIAL_DELAY_SECONDS
138-
+ (frame_index - 1) * self.FRAME_INTERVAL_SECONDS,
139-
partial(self._show_frame, frame_index),
140-
name=f"title-shimmer-{frame_index}",
141-
)
133+
self.set_timer(
134+
self.INITIAL_DELAY_SECONDS,
135+
self._start_shimmer,
136+
name="title-shimmer-start",
137+
)
138+
139+
def _start_shimmer(self) -> None:
140+
"""Advance frames on one interval timer so they can never reorder.
141+
142+
Independent per-frame timers whose deadlines sit closer together
143+
than the platform timer resolution (notably Windows) may fire out
144+
of order, ending the pass on a shimmer frame instead of the title.
145+
"""
146+
self._show_frame(1)
147+
self._next_frame_index = 2
148+
self._shimmer_timer = self.set_interval(
149+
self.FRAME_INTERVAL_SECONDS,
150+
self._advance_frame,
151+
name="title-shimmer",
152+
)
153+
154+
def _advance_frame(self) -> None:
155+
"""Show the next frame and stop the interval after the last one."""
156+
self._show_frame(self._next_frame_index)
157+
if self._next_frame_index >= len(self.frames) - 1:
158+
self._shimmer_timer.stop()
159+
else:
160+
self._next_frame_index += 1
142161

143162
def _show_frame(self, frame_index: int) -> None:
144163
"""Swap colour spans without recalculating the stable title layout."""

‎tests/ui/test_integration.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def recording_show_frame(self, frame_index):
180180
if shown_frames and shown_frames[-1] == last_frame_index:
181181
break
182182
await pilot.pause(0.05)
183-
assert shown_frames and shown_frames[-1] == last_frame_index
183+
assert shown_frames == list(range(1, len(title.frames)))
184184

185185
rendered = title.render()
186186
assert rendered.plain == title.frames[-1].plain

0 commit comments

Comments
 (0)