diff --git a/bar_filler_spinner.go b/bar_filler_spinner.go index a28470d..0fdb523 100644 --- a/bar_filler_spinner.go +++ b/bar_filler_spinner.go @@ -4,7 +4,6 @@ "io" "strings" - "github.com/acarl005/stripansi" "github.com/mattn/go-runewidth" "github.com/vbauerster/mpb/v8/decor" "github.com/vbauerster/mpb/v8/internal" @@ -15,32 +14,41 @@ positionRight ) +var defaultSpinnerStyle = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"} + // SpinnerStyleComposer interface. type SpinnerStyleComposer interface { BarFillerBuilder PositionLeft() SpinnerStyleComposer PositionRight() SpinnerStyleComposer + Meta(func(string) string) SpinnerStyleComposer } type sFiller struct { + position uint count uint - position uint frames []string + meta func(string) string } type spinnerStyle struct { position uint frames []string + meta func(string) string } // SpinnerStyle constructs default spinner style which can be altered via // SpinnerStyleComposer interface. func SpinnerStyle(frames ...string) SpinnerStyleComposer { - ss := new(spinnerStyle) + ss := &spinnerStyle{ + meta: func(s string) string { + return s + }, + } if len(frames) != 0 { - ss.frames = append(ss.frames, frames...) + ss.frames = frames } else { - ss.frames = []string{"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"} + ss.frames = defaultSpinnerStyle } return ss } @@ -55,10 +63,16 @@ return s } +func (s *spinnerStyle) Meta(fn func(string) string) SpinnerStyleComposer { + s.meta = fn + return s +} + func (s *spinnerStyle) Build() BarFiller { sf := &sFiller{ position: s.position, frames: s.frames, + meta: s.meta, } return sf } @@ -67,7 +81,8 @@ width := internal.CheckRequestedWidth(stat.RequestedWidth, stat.AvailableWidth) frame := s.frames[s.count%uint(len(s.frames))] - frameWidth := runewidth.StringWidth(stripansi.Strip(frame)) + frameWidth := runewidth.StringWidth(frame) + frame = s.meta(frame) if width < frameWidth { return nil