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
This commit is contained in:
Yurii Rashkovskii
2023-06-13 12:48:00 -04:00
committed by Christian Rocha
parent afd7868712
commit fe31dc0a97
+7 -2
View File
@@ -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