diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-10 07:50:47 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-10 07:50:47 +0200 |
| commit | ea56e858a0b2194f540b9bf7523b9fbf4691863b (patch) | |
| tree | 4c933a0ab9cd108c93e481d3ca033f2d3122f125 /internal | |
| parent | 599c1bd9331960e92dee72feff11e67d5f76c3df (diff) | |
tui/flamegraph: centralize animation tick scheduling (task 422)
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/tui/flamegraph/model.go | 20 | ||||
| -rw-r--r-- | internal/tui/flamegraph/model_test.go | 16 |
2 files changed, 23 insertions, 13 deletions
diff --git a/internal/tui/flamegraph/model.go b/internal/tui/flamegraph/model.go index 16f82b6..2238ba0 100644 --- a/internal/tui/flamegraph/model.go +++ b/internal/tui/flamegraph/model.go @@ -172,18 +172,12 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.frames = m.animation.CurrentFrames() m.clampSelection() m.subtreeSet = computeSubtreeSetInto(m.frames, m.selectedIdx, m.subtreeSet) - if m.animating { - return m, animTickCmd() - } - return m, nil + return m, m.animationTickCmd() case tea.WindowSizeMsg: m.width = msg.Width m.height = msg.Height m.rebuildFrames(true) - if m.animating { - return m, animTickCmd() - } - return m, nil + return m, m.animationTickCmd() case tea.MouseClickMsg: _ = m.handleMouseClick(msg) return m, nil @@ -430,10 +424,7 @@ func (m Model) HasSnapshot() bool { // AnimationCmd returns a frame animation tick command when animation is active. func (m Model) AnimationCmd() tea.Cmd { - if !m.animating { - return nil - } - return animTickCmd() + return m.animationTickCmd() } // Paused reports whether live refresh is paused. @@ -771,7 +762,10 @@ func abs(v int) int { return v } -func animTickCmd() tea.Cmd { +func (m Model) animationTickCmd() tea.Cmd { + if !m.animating { + return nil + } return tea.Tick(animFrameDuration, func(time.Time) tea.Msg { return animTickMsg{} }) } diff --git a/internal/tui/flamegraph/model_test.go b/internal/tui/flamegraph/model_test.go index f83ccff..23c44e1 100644 --- a/internal/tui/flamegraph/model_test.go +++ b/internal/tui/flamegraph/model_test.go @@ -1056,6 +1056,22 @@ func TestDataRefreshAnimationConvergesOverTicks(t *testing.T) { } } +func TestAnimationCmdFollowsAnimatingState(t *testing.T) { + m := NewModel(nil) + if cmd := m.AnimationCmd(); cmd != nil { + t.Fatalf("expected no animation command when model is idle") + } + + m.animating = true + cmd := m.AnimationCmd() + if cmd == nil { + t.Fatalf("expected animation command when model is animating") + } + if _, ok := cmd().(animTickMsg); !ok { + t.Fatalf("expected animation command to emit animTickMsg") + } +} + func TestRebuildKeepsSelectionOnVisibleRowsWhenTruncated(t *testing.T) { m := NewModel(nil) m.width = 80 |
