-
-
Notifications
You must be signed in to change notification settings - Fork 187
/
main.go
40 lines (35 loc) · 1.23 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"time"
"github.com/pterm/pterm"
)
func main() {
// Start a new fullscreen centered area.
// This area will be used to display the bar chart.
area, _ := pterm.DefaultArea.WithFullscreen().WithCenter().Start()
// Ensure the area stops updating when we're done.
defer area.Stop()
// Loop to update the bar chart 10 times.
for i := 0; i < 10; i++ {
// Create a new bar chart with dynamic bars.
// The bars will change based on the current iteration.
barchart := pterm.DefaultBarChart.WithBars(dynamicBars(i))
// Render the bar chart to a string.
// This string will be used to update the area.
content, _ := barchart.Srender()
// Update the area with the new bar chart.
area.Update(content)
// Wait for half a second before the next update.
time.Sleep(500 * time.Millisecond)
}
}
// dynamicBars generates a set of bars for the bar chart.
// The bars will change based on the current iteration.
func dynamicBars(i int) pterm.Bars {
return pterm.Bars{
{Label: "A", Value: 10}, // A static bar.
{Label: "B", Value: 20 * i}, // A bar that grows with each iteration.
{Label: "C", Value: 30}, // Another static bar.
{Label: "D", Value: 40 + i}, // A bar that grows slowly with each iteration.
}
}