Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(progress): Percent() now return progress as presented visually #132

Merged
merged 1 commit into from Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions progress/progress.go
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