summaryrefslogtreecommitdiffstats
path: root/progress.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-04-06 07:09:38 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-04-06 07:09:38 -0700
commit57378c31cb26336c59114486ed357283fde73cfe (patch)
tree94adaf13100c632d34fb3b0762d76c3e744dbb18 /progress.go
parent045737f983446d8a28b493518dd39b8c6ac02c33 (diff)
downloadprogress-bar-57378c31cb26336c59114486ed357283fde73cfe.tar.zst
Make sure measurements are increasing
Diffstat (limited to 'progress.go')
-rw-r--r--progress.go6
1 files changed, 5 insertions, 1 deletions
diff --git a/progress.go b/progress.go
index 2d78cef..0f1a785 100644
--- a/progress.go
+++ b/progress.go
@@ -47,6 +47,10 @@ func New(max int) *Bar {
// Set sets the current value to val.
func (b *Bar) Set(val int) {
+ // Measurements must be strictly increasing
+ for b.measurements.Len() > 0 && b.measurements.Get(b.measurements.Len()-1).i > val {
+ b.measurements.PopBack()
+ }
b.measurements.PushBack(measurement{time.Now(), val})
}
@@ -57,7 +61,7 @@ func (b *Bar) Print() {
}
now := time.Now()
- for b.measurements.Len() > 1 && now.Sub(b.measurements.Get(0).t) > 2*time.Minute {
+ for b.measurements.Len() > 2 && now.Sub(b.measurements.Get(0).t) > 2*time.Minute {
b.measurements.PopFront()
}
first := b.measurements.Get(0)