From fe31dc0a97e7d1a1670d02353ad8f2ad61b4df7b Mon Sep 17 00:00:00 2001 From: Yurii Rashkovskii Date: Mon, 12 Jun 2023 22:04:00 -0700 Subject: [PATCH] Problem: can't determine if the progress bar stopped updating This would be useful to know to stop displaying it after the user was shown the progress bar to render to its end. Solution: expose `IsComplete` method is based on what's been drawn --- progress/progress.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/progress/progress.go b/progress/progress.go index caeaf10..871d35d 100644 --- a/progress/progress.go +++ b/progress/progress.go @@ -211,8 +211,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } // If we've more or less reached equilibrium, stop updating. - dist := math.Abs(m.percentShown - m.targetPercent) - if dist < 0.001 && m.velocity < 0.01 { + if !m.IsAnimating() { return m, nil } @@ -362,6 +361,12 @@ func max(a, b int) int { return b } +// IsAnimating returns false if the progress bar reached equilibrium and is no longer animating. +func (m *Model) IsAnimating() bool { + dist := math.Abs(m.percentShown - m.targetPercent) + return !(dist < 0.001 && m.velocity < 0.01) +} + func min(a, b int) int { if a < b { return a