Skip to content

Instantly share code, notes, and snippets.

@sheepla
Last active January 26, 2025 22:30
Show Gist options
  • Save sheepla/bfcd4e92e5e7f10ce0265acf9056b13e to your computer and use it in GitHub Desktop.
Save sheepla/bfcd4e92e5e7f10ce0265acf9056b13e to your computer and use it in GitHub Desktop.
Progress bar implementation in Go with github.com/cheggaaa/pb/v3
package main
import (
"progressbar_example/progress"
"time"
)
func main() {
count := 10000
bar := progress.NewProgressBar(int64(count))
bar.
Start()
defer bar.Finish()
for i := 0; i < count; i++ {
bar.Increment()
time.Sleep(1 * time.Millisecond)
}
}
package progress
import (
"time"
pb "github.com/cheggaaa/pb/v3"
)
func NewProgressBar(count int64) *pb.ProgressBar {
return pb.New64(count).
SetTemplate(
` Progress: {{ bar . "[" "▉" (cycle . "⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏") "." "]"}} {{ percent . }} `,
).
SetRefreshRate(100 * time.Millisecond)
}
@sheepla
Copy link
Author

sheepla commented Jan 26, 2025

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment