Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/elulcao/progress-bar

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/elulcao/progress-bar

  • v0.1.1
  • Source
  • Go
  • Socket score

Version published
Created
Source

progress-bar

Go CI CodeQl CI


Demo 01


Another simple progress bar, but with a package installer flavor. The progress bar displays the progress like the well known package manager. This version adapts well to the windows size, small or big window size the progress bar will adapt to the change; the progress bar will adapt to the window size automatically.

Last line of the window is preserved to show the progress, the rest of the window is used to show the program output that consumes the progress-bar.

Characters used by default are "#" and "." but can be changed by updating the struct:

type PBar struct {
    //...
    DoneStr    = "#"
    OngoingStr = "."
    //...
}

Usage

The progress-bar.go should be modified to your needs, currently implementation is limited to printing numbers from 1 to 100. In a real world scenario, the count variable should be used to be updated by another routine in your code.

 for count := 1; count <= pBar.Total; count++ {
    pBar.renderPBar(count)
    time.Sleep(time.Second)    // sleep for 1 second
    fmt.Println(count)         // Update here to your needs
 }

The main.go file can be used to test the progress bar. It is not used in the real world, but it can be used as a reference.

go run main.go

Notes

The progress-bar has to handler, syscall.SIGWINCH and syscall.SIGTERM, the first one is used to detect the window size change and the second one is used to detect the program termination. These handlers can be removed if not needed, your driver code should be able to handle the interruptions.

progress-bar_test.go is used to test the progress bar but the most basic usabillity since the test is executed without a TTY. Due to this, the re-size of the window is not validated for now. It's highly recommended to verify the progress_bar.go via go run main.go to ensure the correct output.

FAQs

Package last updated on 03 Jun 2023

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