diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2019-06-24 21:29:31 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2019-06-24 21:29:31 +0200 |
commit | 2388222e98462fdbbe44f3e091b2b79d80956a9a (patch) | |
tree | 17078d861c20a3e48b19c750c6864c5f59248386 /vendor/github.com/vbauerster/mpb/bar_filler.go | |
parent | a1a4a75abee2c381483a218e1660621ee416ef7c (diff) | |
download | podman-2388222e98462fdbbe44f3e091b2b79d80956a9a.tar.gz podman-2388222e98462fdbbe44f3e091b2b79d80956a9a.tar.bz2 podman-2388222e98462fdbbe44f3e091b2b79d80956a9a.zip |
update dependencies
Ran a `go get -u` and bumped K8s deps to 1.15.0.
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/vbauerster/mpb/bar_filler.go')
-rw-r--r-- | vendor/github.com/vbauerster/mpb/bar_filler.go | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/vendor/github.com/vbauerster/mpb/bar_filler.go b/vendor/github.com/vbauerster/mpb/bar_filler.go new file mode 100644 index 000000000..4e9285ca5 --- /dev/null +++ b/vendor/github.com/vbauerster/mpb/bar_filler.go @@ -0,0 +1,111 @@ +package mpb + +import ( + "io" + "unicode/utf8" + + "github.com/vbauerster/mpb/decor" + "github.com/vbauerster/mpb/internal" +) + +const ( + rLeft = iota + rFill + rTip + rEmpty + rRight + rRevTip + rRefill +) + +var defaultBarStyle = "[=>-]<+" + +type barFiller struct { + format [][]byte + refillAmount int64 + reverse bool +} + +func newDefaultBarFiller() Filler { + bf := &barFiller{ + format: make([][]byte, utf8.RuneCountInString(defaultBarStyle)), + } + bf.setStyle(defaultBarStyle) + return bf +} + +func (s *barFiller) setStyle(style string) { + if !utf8.ValidString(style) { + return + } + src := make([][]byte, 0, utf8.RuneCountInString(style)) + for _, r := range style { + src = append(src, []byte(string(r))) + } + copy(s.format, src) +} + +func (s *barFiller) setReverse() { + s.reverse = true +} + +func (s *barFiller) SetRefill(amount int64) { + s.refillAmount = amount +} + +func (s *barFiller) Fill(w io.Writer, width int, stat *decor.Statistics) { + + // don't count rLeft and rRight [brackets] + width -= 2 + if width < 2 { + return + } + + w.Write(s.format[rLeft]) + if width == 2 { + w.Write(s.format[rRight]) + return + } + + bb := make([][]byte, width) + + cwidth := int(internal.Percentage(stat.Total, stat.Current, int64(width))) + + for i := 0; i < cwidth; i++ { + bb[i] = s.format[rFill] + } + + if s.refillAmount > 0 { + var rwidth int + if s.refillAmount > stat.Current { + rwidth = cwidth + } else { + rwidth = int(internal.Percentage(stat.Total, int64(s.refillAmount), int64(width))) + } + for i := 0; i < rwidth; i++ { + bb[i] = s.format[rRefill] + } + } + + if cwidth > 0 && cwidth < width { + bb[cwidth-1] = s.format[rTip] + } + + for i := cwidth; i < width; i++ { + bb[i] = s.format[rEmpty] + } + + if s.reverse { + if cwidth > 0 && cwidth < width { + bb[cwidth-1] = s.format[rRevTip] + } + for i := len(bb) - 1; i >= 0; i-- { + w.Write(bb[i]) + } + } else { + for i := 0; i < len(bb); i++ { + w.Write(bb[i]) + } + } + w.Write(s.format[rRight]) +} |