summaryrefslogtreecommitdiffstats
path: root/progress.go
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-04-05 14:24:07 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-04-05 14:24:07 -0700
commit049211d719574b9af8453b044d56625fa4af39af (patch)
treeb4b3c473afc0242b5f69a7e3ffbe65d99ec27bbd /progress.go
parent08f8aa62eeaa2ad0ed9a3f299e471c7b2fe98ee3 (diff)
downloadprogress-bar-049211d719574b9af8453b044d56625fa4af39af.tar.zst
Fix bugs
Diffstat (limited to 'progress.go')
-rw-r--r--progress.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/progress.go b/progress.go
index da7cef0..ddc810a 100644
--- a/progress.go
+++ b/progress.go
@@ -5,7 +5,7 @@
// import (
// time"
//
-// "gitlab.com/rhogenson/progress-bar/progress"
+// "gitlab.com/rhogenson/progress-bar"
// )
//
// func main() {
@@ -43,6 +43,9 @@ type Bar struct {
// Set sets the current value to val. val must be between 0 and 1, inclusive.
func (b *Bar) Set(val float64) {
+ if !(0 <= val && val <= 1) {
+ panic(fmt.Sprintf("progress.Bar.Set: value must be between 0 and 1 (got %f)", val))
+ }
if b.measurements.Len() == measurements {
b.measurements.PopFront()
}
@@ -51,6 +54,10 @@ func (b *Bar) Set(val float64) {
// Print shows the progress bar on standard error.
func (b *Bar) Print() {
+ if b.measurements.Len() == 0 {
+ return
+ }
+
first := b.measurements.Get(0)
last := b.measurements.Get(b.measurements.Len() - 1)
deltaT := last.t.Sub(first.t)