https://github.com/fireflycons/yanprogress
Yet ANother Progress Bar
https://github.com/fireflycons/yanprogress
Last synced: about 1 year ago
JSON representation
Yet ANother Progress Bar
- Host: GitHub
- URL: https://github.com/fireflycons/yanprogress
- Owner: fireflycons
- License: mit
- Created: 2024-10-03T17:40:48.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-10-07T10:17:10.000Z (over 1 year ago)
- Last Synced: 2025-04-03T02:42:22.120Z (about 1 year ago)
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yanprogress
Yet ANother Progress Bar :smile:
Dead simple no-frills progress bar that writes by default to stderr.
There are two types
* Bounded - where the total number of iterations to process is known in advance. This will produce a bar output like this
```
[==============> ] 50% (19.7 it/s)
```
* Unbounded - where the total number of iterations to process is not known in advance. This will produce a spinner output like this
```
⠋ (19.8 it/s)
```
If the terminal is not a tty (destination is a file or redirected), then it will produce sequential output like this, without the percentage if unbounded.
```
9% (18.0 it/s)
19% (19.0 it/s)
28% (19.3 it/s)
39% (19.5 it/s)
49% (19.6 it/s)
```
You may optionally add a status to say what it is doing. This can be called at any point to update the status line, in which case it looks like this
```
Frobbing the turnips
[==============> ] 50% (19.7 it/s)
```
## Examples
Bounded progress bar. To use unbounded set the first argument to zero
```go
bar := NewProgressBar(100, 500*time.Millisecond)
bar.SetStatus("Downloading File")
bar.Start()
// Simulate work
for i := 0; i <= 100; i++ {
time.Sleep(50 * time.Millisecond)
bar.Inc()
if i == 50 {
bar.SetStatus("Half way there!")
}
}
bar.Complete()
```
Write to stdout
```go
bar := NewProgressBar(100, 500*time.Millisecond, WithWriter(os.Stdout))
```