| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"sync" |
| 6 |
"time" |
| 7 |
|
| 8 |
"github.com/gosuri/uiprogress" |
| 9 |
) |
| 10 |
|
| 11 |
func main() { |
| 12 |
waitTime := time.Millisecond * 200 |
| 13 |
p := uiprogress.New() |
| 14 |
p.Start() |
| 15 |
|
| 16 |
var wg sync.WaitGroup |
| 17 |
|
| 18 |
bar1 := p.AddBar(20).AppendCompleted().PrependElapsed() |
| 19 |
wg.Add(1) |
| 20 |
go func() { |
| 21 |
defer wg.Done() |
| 22 |
for bar1.Incr() { |
| 23 |
time.Sleep(waitTime) |
| 24 |
} |
| 25 |
fmt.Fprintln(p.Bypass(), "Bar1 finished") |
| 26 |
}() |
| 27 |
|
| 28 |
bar2 := p.AddBar(40).AppendCompleted().PrependElapsed() |
| 29 |
wg.Add(1) |
| 30 |
go func() { |
| 31 |
defer wg.Done() |
| 32 |
for bar2.Incr() { |
| 33 |
time.Sleep(waitTime) |
| 34 |
} |
| 35 |
fmt.Fprintln(p.Bypass(), "Bar2 finished") |
| 36 |
}() |
| 37 |
|
| 38 |
time.Sleep(time.Second) |
| 39 |
bar3 := p.AddBar(20).PrependElapsed().AppendCompleted() |
| 40 |
wg.Add(1) |
| 41 |
go func() { |
| 42 |
defer wg.Done() |
| 43 |
for bar3.Incr() { |
| 44 |
time.Sleep(waitTime) |
| 45 |
} |
| 46 |
fmt.Fprintln(p.Bypass(), "Bar3 finished") |
| 47 |
}() |
| 48 |
|
| 49 |
wg.Wait() |
| 50 |
} |