Socket
Socket
Sign inDemoInstall

github.com/minomino/minprogress

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/minomino/minprogress


Version published
Created
Source

minprogress

minprogress

A progress bar for Go that can also track the speed of progress.

Example of it used in conjuction with minterm. GIF of progress bar using minterm.

Usage

###Import

import "github.com/MinoMino/minprogress"

###Simple Use Make 5 units of progress every second while printing the bar every second:

const total = 50
pb := minprogress.NewProgressBar(total)
tick := time.Tick(time.Millisecond * 200)
go func() {
  for {
    <-tick
    pb.Progress(1)
  }
}()

for {
  if pb.Progress(0) == total {
    fmt.Println("Done!")
    break
  } else {
    fmt.Println(pb.String())
    time.Sleep(time.Second)
  }
}

Output:

[...]
   60% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ (30/50)
   70% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ (35/50)
   80% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘ (40/50)
   90% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘ (45/50)
Done!

###Advanced Use Simulate concurrent file downloads and track download speed:

const total = 50
const workerCount = 10
pb := minprogress.NewProgressBar(total)
pb.SpeedUnits = minprogress.DataUnits
// For nicer output, tell it the singular and plural name of the units.
pb.Unit = "file"
pb.Units = "files"

go func() {
  // Keep only workerCount number of goroutines working concurrently.
  workerQueue := make(chan struct{}, workerCount)
  for i := 0; i < total; i++ {
    workerQueue <- struct{}{}
    go func(uid int) {
      // 200KiB - 1 MiB
      size := rand.Intn(800000) + 200000
      downloaded := 0
      for downloaded < size {
        // Download 1 - 10 KiB every 100 - 200 ms.
        time.Sleep(time.Millisecond*time.Duration(rand.Intn(100)) + 100)
        got := rand.Intn(9000) + 1000
        // Use worker number as UID.
        pb.Report(uid, got)
        downloaded += got
      }
      // Report we're done with this particular download.
      pb.Done(uid)
      // Since one download doesn't necessarily mean one unit of progress,
      // we must also tell the progress bar we made some progress.
      pb.Progress(1)
      // Tell queue we're done.
      <-workerQueue
    }(i)
  }
}()

for {
  if pb.Progress(0) == total {
    fmt.Println("Done!")
    break
  } else {
    fmt.Println(pb.String())
    time.Sleep(time.Second)
  }
}

Output:

[...]
   82% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘ (41/50) files [3.4 MiB/s]
   88% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘ (44/50) files [1.9 MiB/s]
   92% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘ (46/50) files [1.3 MiB/s]
   94% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘ (47/50) files [730.5 KiB/s]
   94% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘ (47/50) files [704.7 KiB/s]
   96% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘ (48/50) files [764.3 KiB/s]
   98% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘ (49/50) files [356.9 KiB/s]
   98% β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘ (49/50) files [259.5 KiB/s]
Done!

License

MIT. See LICENSE for details.

FAQs

Package last updated on 25 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚑️ by Socket Inc