diff options
Diffstat (limited to 'progress.go')
| -rw-r--r-- | progress.go | 9 |
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) |
