fix(deps): update module github.com/vbauerster/mpb/v8 to v8.10.0

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
renovate[bot]
2025-05-02 06:13:38 +00:00
committed by GitHub
parent 7800db68a9
commit 039679d0ae
7 changed files with 107 additions and 84 deletions

View File

@ -15,10 +15,10 @@ const (
iFiller
iTip
iPadding
components
iLen
)
var defaultBarStyle = [components]string{"[", "]", "+", "=", ">", "-"}
var defaultBarStyle = [iLen]string{"[", "]", "+", "=", ">", "-"}
// BarStyleComposer interface.
type BarStyleComposer interface {
@ -44,15 +44,17 @@ type component struct {
bytes []byte
}
type flushSection struct {
meta func(io.Writer, []byte) error
type barSection struct {
meta func(string) string
bytes []byte
}
type bFiller struct {
components [components]component
meta [components]func(io.Writer, []byte) error
flush func(io.Writer, ...flushSection) error
type barSections [iLen]barSection
type barFiller struct {
components [iLen]component
metas [iLen]func(string) string
flushOp func(barSections, io.Writer) error
tip struct {
onComplete bool
count uint
@ -61,8 +63,8 @@ type bFiller struct {
}
type barStyle struct {
style [components]string
metaFuncs [components]func(io.Writer, []byte) error
style [iLen]string
metas [iLen]func(string) string
tipFrames []string
tipOnComplete bool
rev bool
@ -75,9 +77,6 @@ func BarStyle() BarStyleComposer {
style: defaultBarStyle,
tipFrames: []string{defaultBarStyle[iTip]},
}
for i := range bs.metaFuncs {
bs.metaFuncs[i] = defaultMeta
}
return bs
}
@ -87,7 +86,9 @@ func (s barStyle) Lbound(bound string) BarStyleComposer {
}
func (s barStyle) LboundMeta(fn func(string) string) BarStyleComposer {
s.metaFuncs[iLbound] = makeMetaFunc(fn)
if fn != nil && len(fn("")) != 0 {
s.metas[iLbound] = fn
}
return s
}
@ -97,7 +98,9 @@ func (s barStyle) Rbound(bound string) BarStyleComposer {
}
func (s barStyle) RboundMeta(fn func(string) string) BarStyleComposer {
s.metaFuncs[iRbound] = makeMetaFunc(fn)
if fn != nil && len(fn("")) != 0 {
s.metas[iRbound] = fn
}
return s
}
@ -107,7 +110,9 @@ func (s barStyle) Filler(filler string) BarStyleComposer {
}
func (s barStyle) FillerMeta(fn func(string) string) BarStyleComposer {
s.metaFuncs[iFiller] = makeMetaFunc(fn)
if fn != nil && len(fn("")) != 0 {
s.metas[iFiller] = fn
}
return s
}
@ -117,7 +122,9 @@ func (s barStyle) Refiller(refiller string) BarStyleComposer {
}
func (s barStyle) RefillerMeta(fn func(string) string) BarStyleComposer {
s.metaFuncs[iRefiller] = makeMetaFunc(fn)
if fn != nil && len(fn("")) != 0 {
s.metas[iRefiller] = fn
}
return s
}
@ -127,7 +134,9 @@ func (s barStyle) Padding(padding string) BarStyleComposer {
}
func (s barStyle) PaddingMeta(fn func(string) string) BarStyleComposer {
s.metaFuncs[iPadding] = makeMetaFunc(fn)
if fn != nil && len(fn("")) != 0 {
s.metas[iPadding] = fn
}
return s
}
@ -139,7 +148,9 @@ func (s barStyle) Tip(frames ...string) BarStyleComposer {
}
func (s barStyle) TipMeta(fn func(string) string) BarStyleComposer {
s.metaFuncs[iTip] = makeMetaFunc(fn)
if fn != nil && len(fn("")) != 0 {
s.metas[iTip] = fn
}
return s
}
@ -154,9 +165,7 @@ func (s barStyle) Reverse() BarStyleComposer {
}
func (s barStyle) Build() BarFiller {
bf := &bFiller{
meta: s.metaFuncs,
}
bf := &barFiller{metas: s.metas}
bf.components[iLbound] = component{
width: runewidth.StringWidth(s.style[iLbound]),
bytes: []byte(s.style[iLbound]),
@ -186,34 +195,14 @@ func (s barStyle) Build() BarFiller {
}
}
if s.rev {
bf.flush = func(w io.Writer, sections ...flushSection) error {
for i := len(sections) - 1; i >= 0; i-- {
if s := sections[i]; len(s.bytes) != 0 {
err := s.meta(w, s.bytes)
if err != nil {
return err
}
}
}
return nil
}
bf.flushOp = barSections.flushRev
} else {
bf.flush = func(w io.Writer, sections ...flushSection) error {
for _, s := range sections {
if len(s.bytes) != 0 {
err := s.meta(w, s.bytes)
if err != nil {
return err
}
}
}
return nil
}
bf.flushOp = barSections.flush
}
return bf
}
func (s *bFiller) Fill(w io.Writer, stat decor.Statistics) error {
func (s *barFiller) Fill(w io.Writer, stat decor.Statistics) error {
width := internal.CheckRequestedWidth(stat.RequestedWidth, stat.AvailableWidth)
// don't count brackets as progress
width -= (s.components[iLbound].width + s.components[iRbound].width)
@ -221,15 +210,6 @@ func (s *bFiller) Fill(w io.Writer, stat decor.Statistics) error {
return nil
}
err := s.meta[iLbound](w, s.components[iLbound].bytes)
if err != nil {
return err
}
if width == 0 {
return s.meta[iRbound](w, s.components[iRbound].bytes)
}
var tip component
var refilling, filling, padding []byte
var fillCount int
@ -265,26 +245,50 @@ func (s *bFiller) Fill(w io.Writer, stat decor.Statistics) error {
padding = append(padding, "…"...)
}
err = s.flush(w,
flushSection{s.meta[iRefiller], refilling},
flushSection{s.meta[iFiller], filling},
flushSection{s.meta[iTip], tip.bytes},
flushSection{s.meta[iPadding], padding},
)
return s.flushOp(barSections{
{s.metas[iLbound], s.components[iLbound].bytes},
{s.metas[iRbound], s.components[iRbound].bytes},
{s.metas[iRefiller], refilling},
{s.metas[iFiller], filling},
{s.metas[iTip], tip.bytes},
{s.metas[iPadding], padding},
}, w)
}
func (s barSection) flush(w io.Writer) (err error) {
if s.meta != nil {
_, err = io.WriteString(w, s.meta(string(s.bytes)))
} else {
_, err = w.Write(s.bytes)
}
return err
}
func (bb barSections) flush(w io.Writer) error {
err := bb[0].flush(w)
if err != nil {
return err
}
return s.meta[iRbound](w, s.components[iRbound].bytes)
for _, s := range bb[2:] {
err := s.flush(w)
if err != nil {
return err
}
}
return bb[1].flush(w)
}
func makeMetaFunc(fn func(string) string) func(io.Writer, []byte) error {
return func(w io.Writer, p []byte) (err error) {
_, err = io.WriteString(w, fn(string(p)))
func (bb barSections) flushRev(w io.Writer) error {
err := bb[0].flush(w)
if err != nil {
return err
}
}
func defaultMeta(w io.Writer, p []byte) (err error) {
_, err = w.Write(p)
return err
ss := bb[2:]
for i := len(ss) - 1; i >= 0; i-- {
err := ss[i].flush(w)
if err != nil {
return err
}
}
return bb[1].flush(w)
}

View File

@ -24,7 +24,7 @@ type SpinnerStyleComposer interface {
Meta(func(string) string) SpinnerStyleComposer
}
type sFiller struct {
type spinnerFiller struct {
frames []string
count uint
meta func(string) string
@ -40,9 +40,7 @@ type spinnerStyle struct {
// SpinnerStyle constructs default spinner style which can be altered via
// SpinnerStyleComposer interface.
func SpinnerStyle(frames ...string) SpinnerStyleComposer {
ss := spinnerStyle{
meta: func(s string) string { return s },
}
ss := spinnerStyle{meta: func(s string) string { return s }}
if len(frames) != 0 {
ss.frames = frames
} else {
@ -62,12 +60,14 @@ func (s spinnerStyle) PositionRight() SpinnerStyleComposer {
}
func (s spinnerStyle) Meta(fn func(string) string) SpinnerStyleComposer {
s.meta = fn
if fn != nil && len(fn("")) != 0 {
s.meta = fn
}
return s
}
func (s spinnerStyle) Build() BarFiller {
sf := &sFiller{
sf := &spinnerFiller{
frames: s.frames,
meta: s.meta,
}
@ -88,7 +88,7 @@ func (s spinnerStyle) Build() BarFiller {
return sf
}
func (s *sFiller) Fill(w io.Writer, stat decor.Statistics) error {
func (s *spinnerFiller) Fill(w io.Writer, stat decor.Statistics) error {
width := internal.CheckRequestedWidth(stat.RequestedWidth, stat.AvailableWidth)
frame := s.frames[s.count%uint(len(s.frames))]
frameWidth := runewidth.StringWidth(frame)

View File

@ -86,6 +86,25 @@ func BarFillerOnComplete(message string) BarOption {
})
}
// BarFillerClearOnAbort clears bar's filler on abort event.
// It's shortcut for BarFillerOnAbort("").
func BarFillerClearOnAbort() BarOption {
return BarFillerOnAbort("")
}
// BarFillerOnAbort replaces bar's filler with message, on abort event.
func BarFillerOnAbort(message string) BarOption {
return BarFillerMiddleware(func(base BarFiller) BarFiller {
return BarFillerFunc(func(w io.Writer, st decor.Statistics) error {
if st.Aborted {
_, err := io.WriteString(w, message)
return err
}
return base.Fill(w, st)
})
})
}
// BarFillerMiddleware provides a way to augment the underlying BarFiller.
func BarFillerMiddleware(middle func(BarFiller) BarFiller) BarOption {
if middle == nil {

View File

@ -1,3 +1,6 @@
//go:generate go tool stringer -type=SizeB1024 -trimprefix=_i
//go:generate go tool stringer -type=SizeB1000 -trimprefix=_
package decor
import (
@ -5,9 +8,6 @@ import (
"strconv"
)
//go:generate stringer -type=SizeB1024 -trimprefix=_i
//go:generate stringer -type=SizeB1000 -trimprefix=_
var (
_ fmt.Formatter = SizeB1024(0)
_ fmt.Stringer = SizeB1024(0)