MCPcopy
hub / github.com/pterm/pterm / main

Function main

_examples/progressbar/multiple/main.go:9–48  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7)
8
9func main() {
10 // Create a multi printer instance from the default one
11 multi := pterm.DefaultMultiPrinter
12
13 // Create five progress bars with a total of 100 units each, and assign each a new writer from the multi printer
14 pb1, _ := pterm.DefaultProgressbar.WithTotal(100).WithWriter(multi.NewWriter()).Start("Progressbar 1")
15 pb2, _ := pterm.DefaultProgressbar.WithTotal(100).WithWriter(multi.NewWriter()).Start("Progressbar 2")
16 pb3, _ := pterm.DefaultProgressbar.WithTotal(100).WithWriter(multi.NewWriter()).Start("Progressbar 3")
17 pb4, _ := pterm.DefaultProgressbar.WithTotal(100).WithWriter(multi.NewWriter()).Start("Progressbar 4")
18 pb5, _ := pterm.DefaultProgressbar.WithTotal(100).WithWriter(multi.NewWriter()).Start("Progressbar 5")
19
20 // Start the multi printer
21 multi.Start()
22
23 // Loop to increment progress bars based on certain conditions
24 for i := 1; i <= 100; i++ {
25 pb1.Increment() // Increment the first progress bar at each iteration
26
27 if i%2 == 0 {
28 pb2.Add(3) // Add 3 units to the second progress bar at every even iteration
29 }
30
31 if i%5 == 0 {
32 pb3.Increment() // Increment the third progress bar at every fifth iteration
33 }
34
35 if i%10 == 0 {
36 pb4.Increment() // Increment the fourth progress bar at every tenth iteration
37 }
38
39 if i%3 == 0 {
40 pb5.Increment() // Increment the fifth progress bar at every third iteration
41 }
42
43 time.Sleep(time.Millisecond * 50) // Pause for 50 milliseconds at each iteration
44 }
45
46 // Stop the multi printer
47 multi.Stop()
48}

Callers

nothing calls this directly

Calls 7

WithTotalMethod · 0.80
NewWriterMethod · 0.80
IncrementMethod · 0.80
StartMethod · 0.45
WithWriterMethod · 0.45
AddMethod · 0.45
StopMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…