Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
7e15092e97 | |||
528a667489 | |||
0cf4a5dc48 |
3 changed files with 17 additions and 6 deletions
3
go.mod
3
go.mod
|
@ -8,6 +8,9 @@ require (
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/kr/pretty v0.3.1 // indirect
|
||||||
|
github.com/kr/text v0.2.0 // indirect
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0 // indirect
|
||||||
golang.org/x/sys v0.27.0 // indirect
|
golang.org/x/sys v0.27.0 // indirect
|
||||||
golang.org/x/text v0.19.0 // indirect
|
golang.org/x/text v0.19.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
8
go.sum
8
go.sum
|
@ -1,7 +1,15 @@
|
||||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
||||||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/nicksnyder/go-i18n/v2 v2.4.1 h1:zwzjtX4uYyiaU02K5Ia3zSkpJZrByARkRB4V3YPrr0g=
|
github.com/nicksnyder/go-i18n/v2 v2.4.1 h1:zwzjtX4uYyiaU02K5Ia3zSkpJZrByARkRB4V3YPrr0g=
|
||||||
github.com/nicksnyder/go-i18n/v2 v2.4.1/go.mod h1:++Pl70FR6Cki7hdzZRnEEqdc2dJt+SAGotyFg/SvZMk=
|
github.com/nicksnyder/go-i18n/v2 v2.4.1/go.mod h1:++Pl70FR6Cki7hdzZRnEEqdc2dJt+SAGotyFg/SvZMk=
|
||||||
|
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||||
|
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||||
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||||
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
||||||
|
|
|
@ -44,18 +44,16 @@ func New(info ProgressInfo) *ProgressBar {
|
||||||
|
|
||||||
func (p *ProgressBar) render(final bool) {
|
func (p *ProgressBar) render(final bool) {
|
||||||
|
|
||||||
p.lock.Lock()
|
|
||||||
defer p.lock.Unlock()
|
|
||||||
|
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
|
|
||||||
numFilled := math.Round((float64(p.currentBytes) / float64(p.maxBytes)) * 40)
|
numFilled := math.Round((float64(p.currentBytes) / float64(p.maxBytes)) * 40)
|
||||||
numBlank := 40 - numFilled
|
numBlank := 40 - numFilled
|
||||||
donePercent := math.Round(float64(p.currentBytes) / float64(p.maxBytes) * 100)
|
donePercent := math.Round(float64(p.currentBytes) / float64(p.maxBytes) * 100)
|
||||||
|
|
||||||
if int(donePercent) == p.currentPercent {
|
if int(donePercent) == p.currentPercent && !final {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
p.currentPercent = int(donePercent)
|
||||||
|
|
||||||
var blockColor string
|
var blockColor string
|
||||||
|
|
||||||
|
@ -121,7 +119,7 @@ func (p *ProgressBar) render(final bool) {
|
||||||
if width == 0 {
|
if width == 0 {
|
||||||
lineNum = 1
|
lineNum = 1
|
||||||
} else {
|
} else {
|
||||||
lineNum = ((len(removeANSIEscapeCodes(sb.String())) + width - 1) / width)
|
lineNum = (len(removeANSIEscapeCodes(sb.String())) + width - 1) / width
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.hasStarted {
|
if p.hasStarted {
|
||||||
|
@ -142,9 +140,11 @@ func (p *ProgressBar) render(final bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProgressBar) Add(num int64) {
|
func (p *ProgressBar) Add(num int64) {
|
||||||
|
p.lock.Lock()
|
||||||
p.currentBytes = p.currentBytes + num
|
p.currentBytes = p.currentBytes + num
|
||||||
|
|
||||||
p.render(false)
|
p.render(false)
|
||||||
|
p.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ProgressBar) Close() (err error) {
|
func (p *ProgressBar) Close() (err error) {
|
||||||
|
@ -161,7 +161,7 @@ func (p *ProgressBar) Close() (err error) {
|
||||||
if width == 0 {
|
if width == 0 {
|
||||||
lineNum = 1
|
lineNum = 1
|
||||||
} else {
|
} else {
|
||||||
lineNum = ((p.textWidth + width - 1) / width)
|
lineNum = (p.textWidth + width - 1) / width
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < lineNum; i++ {
|
for i := 0; i < lineNum; i++ {
|
||||||
|
|
Loading…
Reference in a new issue