summaryrefslogtreecommitdiff
path: root/progressbar.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-06-30 09:57:44 -0400
committerPietro Gagliardi <[email protected]>2014-06-30 09:57:44 -0400
commit33155f7496a818a1ed83fe49cccb63be7842bc81 (patch)
treebbb14af3d92becf7d5ca5abfb28630a2b413ad93 /progressbar.go
parente032807546a96e6489d18a0e42ced51b7c31a55c (diff)
Reverted everything back to the old API.
Diffstat (limited to 'progressbar.go')
-rw-r--r--progressbar.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/progressbar.go b/progressbar.go
index 875a262..e7c7149 100644
--- a/progressbar.go
+++ b/progressbar.go
@@ -2,11 +2,16 @@
package ui
+import (
+ "sync"
+)
+
// A ProgressBar is a horizontal rectangle that fills up from left to right to indicate the progress of a long-running task.
// This progress is represented by an integer within the range [0,100], representing a percentage.
// Alternatively, a progressbar can show an animation indicating that progress is being made but how much is indeterminate.
// Newly-created ProgressBars default to showing 0% progress.
type ProgressBar struct {
+ lock sync.Mutex
created bool
sysData *sysData
initProg int
@@ -25,6 +30,9 @@ func NewProgressBar() *ProgressBar {
// Otherwise, SetProgress panics.
// Calling SetProgress(-1) repeatedly will neither leave indeterminate mode nor stop any animation involved in indeterminate mode indefinitely; any other side-effect of doing so is implementation-defined.
func (p *ProgressBar) SetProgress(percent int) {
+ p.lock.Lock()
+ defer p.lock.Unlock()
+
if percent < -1 || percent > 100 {
panic("percent value out of range")
}
@@ -36,6 +44,9 @@ func (p *ProgressBar) SetProgress(percent int) {
}
func (p *ProgressBar) make(window *sysData) error {
+ p.lock.Lock()
+ defer p.lock.Unlock()
+
err := p.sysData.make(window)
if err != nil {
return err