https://github.com/elulcao/progress-bar
Progress bar in Go
https://github.com/elulcao/progress-bar
ansi go golang progress-bar progressbar terminal
Last synced: 5 months ago
JSON representation
Progress bar in Go
- Host: GitHub
- URL: https://github.com/elulcao/progress-bar
- Owner: elulcao
- License: apache-2.0
- Created: 2022-02-14T16:16:18.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2026-02-15T21:22:11.000Z (5 months ago)
- Last Synced: 2026-02-16T04:20:33.622Z (5 months ago)
- Topics: ansi, go, golang, progress-bar, progressbar, terminal
- Language: Go
- Homepage:
- Size: 3.63 MB
- Stars: 27
- Watchers: 1
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# progress-bar
[](https://github.com/elulcao/progress-bar/blob/main/.github/workflows/go.yaml)
[](https://github.com/elulcao/progress-bar/blob/main/.github/workflows/codeql-analysis.yaml)
---
---
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:
```go
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.
```go
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
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.