Skip to content

Commit

Permalink
chore(progress): Percent() now return progress as presented visually
Browse files Browse the repository at this point in the history
Prior to this change Percent() returned the target progress to which the
progress bar was animating.
  • Loading branch information
meowgorithm committed Mar 30, 2022
1 parent 8856251 commit d897463
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ type Model struct {
// Members for animated transitions.
spring harmonica.Spring
springCustomized bool
percent float64
targetPercent float64
percentShown float64 // percent currently displaying
targetPercent float64 // percent to which we're animating
velocity float64

// Gradient settings
Expand Down Expand Up @@ -203,12 +203,12 @@ 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.percent - m.targetPercent)
dist := math.Abs(m.percentShown - m.targetPercent)
if dist < 0.001 && m.velocity < 0.01 {
return m, nil
}

m.percent, m.velocity = m.spring.Update(m.percent, m.velocity, m.targetPercent)
m.percentShown, m.velocity = m.spring.Update(m.percentShown, m.velocity, m.targetPercent)
return m, m.nextFrame()

default:
Expand All @@ -224,7 +224,7 @@ func (m *Model) SetSpringOptions(frequency, damping float64) {
m.spring = harmonica.NewSpring(harmonica.FPS(fps), frequency, damping)
}

// Percent returns the current percentage state of the model. This is only
// Percent returns the current visible percentage on the model. This is only
// relevant when you're animating the progress bar.
//
// If you're rendering with ViewAs you won't need this.
Expand Down Expand Up @@ -261,7 +261,7 @@ func (m *Model) DecrPercent(v float64) tea.Cmd {
// View renders the an animated progress bar in its current state. To render
// a static progress bar based on your own calculations use ViewAs instead.
func (m Model) View() string {
return m.ViewAs(m.percent)
return m.ViewAs(m.percentShown)
}

// ViewAs renders the progress bar with a given percentage.
Expand Down

0 comments on commit d897463

Please sign in to comment.