mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
Update progressbar
This commit is contained in:
parent
4574e4816f
commit
bab9ceb1bb
5 changed files with 67 additions and 30 deletions
4
Gopkg.lock
generated
4
Gopkg.lock
generated
|
@ -28,8 +28,8 @@
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/schollz/progressbar"
|
name = "github.com/schollz/progressbar"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "b8e001516e13bd132ed253bf1b175dbfb5cdf308"
|
revision = "98649a7575ca56014cb102885f09f05bb2cccb49"
|
||||||
version = "v0.2.0"
|
version = "v0.3.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/sirupsen/logrus"
|
name = "github.com/sirupsen/logrus"
|
||||||
|
|
43
vendor/github.com/schollz/progressbar/README.md
generated
vendored
43
vendor/github.com/schollz/progressbar/README.md
generated
vendored
|
@ -1,15 +1,21 @@
|
||||||
<p align="center">
|
# progressbar
|
||||||
<img
|
|
||||||
src="logo.png"
|
|
||||||
width="100%" border="0" alt="progressbar">
|
|
||||||
<br>
|
|
||||||
<a href="https://travis-ci.org/schollz/progressbar"><img src="https://travis-ci.org/schollz/progressbar.svg?branch=master" alt="Build Status"></a>
|
|
||||||
<img src="https://img.shields.io/badge/coverage-94%25-brightgreen.svg" alt="Code Coverage">
|
|
||||||
<a href="https://goreportcard.com/report/github.com/schollz/progressbar"><img src="https://goreportcard.com/badge/github.com/schollz/progressbar" alt="Go Report Card"></a>
|
|
||||||
<a href="https://godoc.org/github.com/schollz/progressbar"><img src="https://godoc.org/github.com/schollz/progressbar?status.svg" alt="GoDoc"></a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p align="center">A very simple progress bar.</p>
|
[](https://travis-ci.org/schollz/progressbar)
|
||||||
|
[](https://goreportcard.com/report/github.com/schollz/progressbar)
|
||||||
|

|
||||||
|
[](https://godoc.org/github.com/schollz/progressbar)
|
||||||
|
|
||||||
|
A very simple thread-safe progress bar which should work on every OS without problems. I needed a progressbar for [croc](https://github.com/schollz/croc) and everything I tried had problems, so I made another one.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```
|
||||||
|
go get -u github.com/schollz/progressbar
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
**Basic usage:**
|
**Basic usage:**
|
||||||
|
|
||||||
|
@ -26,3 +32,18 @@ which looks like:
|
||||||
```bash
|
```bash
|
||||||
100% |████████████████████████████████████████| [1s:0s]
|
100% |████████████████████████████████████████| [1s:0s]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The times at the end show the elapsed time and the remaining time, respectively.
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Pull requests are welcome. Feel free to...
|
||||||
|
|
||||||
|
- Revise documentation
|
||||||
|
- Add new features
|
||||||
|
- Fix bugs
|
||||||
|
- Suggest improvements
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
||||||
|
|
4
vendor/github.com/schollz/progressbar/examples/main.go
generated
vendored
4
vendor/github.com/schollz/progressbar/examples/main.go
generated
vendored
|
@ -7,9 +7,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
bar := progressbar.New(100)
|
bar := progressbar.New(1000)
|
||||||
bar.Reset()
|
bar.Reset()
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
bar.Add(1)
|
bar.Add(1)
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
30
vendor/github.com/schollz/progressbar/progressbar.go
generated
vendored
30
vendor/github.com/schollz/progressbar/progressbar.go
generated
vendored
|
@ -35,19 +35,17 @@ type ProgressBar struct {
|
||||||
// New returns a new ProgressBar
|
// New returns a new ProgressBar
|
||||||
// with the specified maximum
|
// with the specified maximum
|
||||||
func New(max int) *ProgressBar {
|
func New(max int) *ProgressBar {
|
||||||
p := new(ProgressBar)
|
return &ProgressBar{
|
||||||
p.Lock()
|
max: max,
|
||||||
defer p.Unlock()
|
size: 40,
|
||||||
p.max = max
|
symbolFinished: "█",
|
||||||
p.size = 40
|
symbolLeft: " ",
|
||||||
p.symbolFinished = "█"
|
leftBookend: "|",
|
||||||
p.symbolLeft = " "
|
rightBookend: "|",
|
||||||
p.leftBookend = "|"
|
w: os.Stdout,
|
||||||
p.rightBookend = "|"
|
lastShown: time.Now(),
|
||||||
p.w = os.Stdout
|
startTime: time.Now(),
|
||||||
p.lastShown = time.Now()
|
}
|
||||||
p.startTime = time.Now()
|
|
||||||
return p
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset will reset the clock that is used
|
// Reset will reset the clock that is used
|
||||||
|
@ -85,6 +83,10 @@ func (p *ProgressBar) Add(num int) error {
|
||||||
// Set will change the current count on the progress bar
|
// Set will change the current count on the progress bar
|
||||||
func (p *ProgressBar) Set(num int) error {
|
func (p *ProgressBar) Set(num int) error {
|
||||||
p.Lock()
|
p.Lock()
|
||||||
|
if p.max == 0 {
|
||||||
|
p.Unlock()
|
||||||
|
return errors.New("max must be greater than 0")
|
||||||
|
}
|
||||||
p.currentNum = num
|
p.currentNum = num
|
||||||
percent := float64(p.currentNum) / float64(p.max)
|
percent := float64(p.currentNum) / float64(p.max)
|
||||||
p.currentSaucerSize = int(percent * float64(p.size))
|
p.currentSaucerSize = int(percent * float64(p.size))
|
||||||
|
@ -112,7 +114,7 @@ func (p *ProgressBar) Show() error {
|
||||||
strings.Repeat(p.symbolFinished, p.currentSaucerSize),
|
strings.Repeat(p.symbolFinished, p.currentSaucerSize),
|
||||||
strings.Repeat(p.symbolLeft, p.size-p.currentSaucerSize),
|
strings.Repeat(p.symbolLeft, p.size-p.currentSaucerSize),
|
||||||
p.rightBookend,
|
p.rightBookend,
|
||||||
time.Since(p.startTime).Round(time.Second).String(),
|
(time.Duration(time.Since(p.startTime).Seconds()) * time.Second).String(),
|
||||||
(time.Duration(secondsLeft) * time.Second).String(),
|
(time.Duration(secondsLeft) * time.Second).String(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
16
vendor/github.com/schollz/progressbar/progressbar_test.go
generated
vendored
16
vendor/github.com/schollz/progressbar/progressbar_test.go
generated
vendored
|
@ -1,6 +1,9 @@
|
||||||
package progressbar
|
package progressbar
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
func ExampleBar() {
|
func ExampleBar() {
|
||||||
bar := New(10)
|
bar := New(10)
|
||||||
|
@ -12,3 +15,14 @@ func ExampleBar() {
|
||||||
// Output:
|
// Output:
|
||||||
// 10% |█ | [1s:9s]
|
// 10% |█ | [1s:9s]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBar(t *testing.T) {
|
||||||
|
bar := New(0)
|
||||||
|
if err := bar.Add(1); err == nil {
|
||||||
|
t.Error("should have an error for 0 bar")
|
||||||
|
}
|
||||||
|
bar = New(10)
|
||||||
|
if err := bar.Add(11); err == nil {
|
||||||
|
t.Error("should have an error for adding > bar")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue