[VOL-5486] Fix deprecated versions
Change-Id: If0b888d6c2f33b2f415c8b03b08dc994bb3df3f4
Signed-off-by: Abhay Kumar <abhay.kumar@radisys.com>
diff --git a/vendor/github.com/cheggaaa/pb/v3/LICENSE b/vendor/github.com/cheggaaa/pb/v3/LICENSE
new file mode 100644
index 0000000..ffe46f0
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/LICENSE
@@ -0,0 +1,12 @@
+Copyright (c) 2012-2024, Sergey Cherepanov
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+* Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/github.com/cheggaaa/pb/v3/element.go b/vendor/github.com/cheggaaa/pb/v3/element.go
new file mode 100644
index 0000000..3882550
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/element.go
@@ -0,0 +1,330 @@
+package pb
+
+import (
+ "bytes"
+ "fmt"
+ "math"
+ "strings"
+ "sync"
+ "time"
+)
+
+const (
+ adElPlaceholder = "%_ad_el_%"
+ adElPlaceholderLen = len(adElPlaceholder)
+)
+
+var (
+ defaultBarEls = [5]string{"[", "-", ">", "_", "]"}
+)
+
+// Element is an interface for bar elements
+type Element interface {
+ ProgressElement(state *State, args ...string) string
+}
+
+// ElementFunc type implements Element interface and created for simplify elements
+type ElementFunc func(state *State, args ...string) string
+
+// ProgressElement just call self func
+func (e ElementFunc) ProgressElement(state *State, args ...string) string {
+ return e(state, args...)
+}
+
+var elementsM sync.Mutex
+
+var elements = map[string]Element{
+ "percent": ElementPercent,
+ "counters": ElementCounters,
+ "bar": adaptiveWrap(ElementBar),
+ "speed": ElementSpeed,
+ "rtime": ElementRemainingTime,
+ "etime": ElementElapsedTime,
+ "string": ElementString,
+ "cycle": ElementCycle,
+}
+
+// RegisterElement give you a chance to use custom elements
+func RegisterElement(name string, el Element, adaptive bool) {
+ if adaptive {
+ el = adaptiveWrap(el)
+ }
+ elementsM.Lock()
+ elements[name] = el
+ elementsM.Unlock()
+}
+
+type argsHelper []string
+
+func (args argsHelper) getOr(n int, value string) string {
+ if len(args) > n {
+ return args[n]
+ }
+ return value
+}
+
+func (args argsHelper) getNotEmptyOr(n int, value string) (v string) {
+ if v = args.getOr(n, value); v == "" {
+ return value
+ }
+ return
+}
+
+func adaptiveWrap(el Element) Element {
+ return ElementFunc(func(state *State, args ...string) string {
+ state.recalc = append(state.recalc, ElementFunc(func(s *State, _ ...string) (result string) {
+ s.adaptive = true
+ result = el.ProgressElement(s, args...)
+ s.adaptive = false
+ return
+ }))
+ return adElPlaceholder
+ })
+}
+
+// ElementPercent shows current percent of progress.
+// Optionally can take one or two string arguments.
+// First string will be used as value for format float64, default is "%.02f%%".
+// Second string will be used when percent can't be calculated, default is "?%"
+// In template use as follows: {{percent .}} or {{percent . "%.03f%%"}} or {{percent . "%.03f%%" "?"}}
+var ElementPercent ElementFunc = func(state *State, args ...string) string {
+ argsh := argsHelper(args)
+ if state.Total() > 0 {
+ return fmt.Sprintf(
+ argsh.getNotEmptyOr(0, "%.02f%%"),
+ float64(state.Value())/(float64(state.Total())/float64(100)),
+ )
+ }
+ return argsh.getOr(1, "?%")
+}
+
+// ElementCounters shows current and total values.
+// Optionally can take one or two string arguments.
+// First string will be used as format value when Total is present (>0). Default is "%s / %s"
+// Second string will be used when total <= 0. Default is "%[1]s"
+// In template use as follows: {{counters .}} or {{counters . "%s/%s"}} or {{counters . "%s/%s" "%s/?"}}
+var ElementCounters ElementFunc = func(state *State, args ...string) string {
+ var f string
+ if state.Total() > 0 {
+ f = argsHelper(args).getNotEmptyOr(0, "%s / %s")
+ } else {
+ f = argsHelper(args).getNotEmptyOr(1, "%[1]s")
+ }
+ return fmt.Sprintf(f, state.Format(state.Value()), state.Format(state.Total()))
+}
+
+type elementKey int
+
+const (
+ barObj elementKey = iota
+ speedObj
+ cycleObj
+)
+
+type bar struct {
+ eb [5][]byte // elements in bytes
+ cc [5]int // cell counts
+ buf *bytes.Buffer
+}
+
+func (p *bar) write(state *State, eln, width int) int {
+ repeat := width / p.cc[eln]
+ remainder := width % p.cc[eln]
+ for i := 0; i < repeat; i++ {
+ p.buf.Write(p.eb[eln])
+ }
+ if remainder > 0 {
+ StripStringToBuffer(string(p.eb[eln]), remainder, p.buf)
+ }
+ return width
+}
+
+func getProgressObj(state *State, args ...string) (p *bar) {
+ var ok bool
+ if p, ok = state.Get(barObj).(*bar); !ok {
+ p = &bar{
+ buf: bytes.NewBuffer(nil),
+ }
+ state.Set(barObj, p)
+ }
+ argsH := argsHelper(args)
+ for i := range p.eb {
+ arg := argsH.getNotEmptyOr(i, defaultBarEls[i])
+ if string(p.eb[i]) != arg {
+ p.cc[i] = CellCount(arg)
+ p.eb[i] = []byte(arg)
+ if p.cc[i] == 0 {
+ p.cc[i] = 1
+ p.eb[i] = []byte(" ")
+ }
+ }
+ }
+ return
+}
+
+// ElementBar make progress bar view [-->__]
+// Optionally can take up to 5 string arguments. Defaults is "[", "-", ">", "_", "]"
+// In template use as follows: {{bar . }} or {{bar . "<" "oOo" "|" "~" ">"}}
+// Color args: {{bar . (red "[") (green "-") ...
+var ElementBar ElementFunc = func(state *State, args ...string) string {
+ // init
+ var p = getProgressObj(state, args...)
+
+ total, value := state.Total(), state.Value()
+ if total < 0 {
+ total = -total
+ }
+ if value < 0 {
+ value = -value
+ }
+
+ // check for overflow
+ if total != 0 && value > total {
+ total = value
+ }
+
+ p.buf.Reset()
+
+ var widthLeft = state.AdaptiveElWidth()
+ if widthLeft <= 0 || !state.IsAdaptiveWidth() {
+ widthLeft = 30
+ }
+
+ // write left border
+ if p.cc[0] < widthLeft {
+ widthLeft -= p.write(state, 0, p.cc[0])
+ } else {
+ p.write(state, 0, widthLeft)
+ return p.buf.String()
+ }
+
+ // check right border size
+ if p.cc[4] < widthLeft {
+ // write later
+ widthLeft -= p.cc[4]
+ } else {
+ p.write(state, 4, widthLeft)
+ return p.buf.String()
+ }
+
+ var curCount int
+
+ if total > 0 {
+ // calculate count of currenct space
+ curCount = int(math.Ceil((float64(value) / float64(total)) * float64(widthLeft)))
+ }
+
+ // write bar
+ if total == value && state.IsFinished() {
+ widthLeft -= p.write(state, 1, curCount)
+ } else if toWrite := curCount - p.cc[2]; toWrite > 0 {
+ widthLeft -= p.write(state, 1, toWrite)
+ widthLeft -= p.write(state, 2, p.cc[2])
+ } else if curCount > 0 {
+ widthLeft -= p.write(state, 2, curCount)
+ }
+ if widthLeft > 0 {
+ widthLeft -= p.write(state, 3, widthLeft)
+ }
+ // write right border
+ p.write(state, 4, p.cc[4])
+ // cut result and return string
+ return p.buf.String()
+}
+
+func elapsedTime(state *State) string {
+ elapsed := state.Time().Sub(state.StartTime())
+ var precision time.Duration
+ var ok bool
+ if precision, ok = state.Get(TimeRound).(time.Duration); !ok {
+ // default behavior: round to nearest .1s when elapsed < 10s
+ //
+ // we compare with 9.95s as opposed to 10s to avoid an annoying
+ // interaction with the fixed precision display code below,
+ // where 9.9s would be rounded to 10s but printed as 10.0s, and
+ // then 10.0s would be rounded to 10s and printed as 10s
+ if elapsed < 9950*time.Millisecond {
+ precision = 100 * time.Millisecond
+ } else {
+ precision = time.Second
+ }
+ }
+ rounded := elapsed.Round(precision)
+ if precision < time.Second && rounded >= time.Second {
+ // special handling to ensure string is shown with the given
+ // precision, with trailing zeros after the decimal point if
+ // necessary
+ reference := (2*time.Second - time.Nanosecond).Truncate(precision).String()
+ // reference looks like "1.9[...]9s", telling us how many
+ // decimal digits we need
+ neededDecimals := len(reference) - 3
+ s := rounded.String()
+ dotIndex := strings.LastIndex(s, ".")
+ if dotIndex != -1 {
+ // s has the form "[stuff].[decimals]s"
+ decimals := len(s) - dotIndex - 2
+ extraZeros := neededDecimals - decimals
+ return fmt.Sprintf("%s%ss", s[:len(s)-1], strings.Repeat("0", extraZeros))
+ } else {
+ // s has the form "[stuff]s"
+ return fmt.Sprintf("%s.%ss", s[:len(s)-1], strings.Repeat("0", neededDecimals))
+ }
+ } else {
+ return rounded.String()
+ }
+}
+
+// ElementRemainingTime calculates remaining time based on speed (EWMA)
+// Optionally can take one or two string arguments.
+// First string will be used as value for format time duration string, default is "%s".
+// Second string will be used when bar finished and value indicates elapsed time, default is "%s"
+// Third string will be used when value not available, default is "?"
+// In template use as follows: {{rtime .}} or {{rtime . "%s remain"}} or {{rtime . "%s remain" "%s total" "???"}}
+var ElementRemainingTime ElementFunc = func(state *State, args ...string) string {
+ if state.IsFinished() {
+ return fmt.Sprintf(argsHelper(args).getOr(1, "%s"), elapsedTime(state))
+ }
+ sp := getSpeedObj(state).value(state)
+ if sp > 0 {
+ remain := float64(state.Total() - state.Value())
+ remainDur := time.Duration(remain/sp) * time.Second
+ return fmt.Sprintf(argsHelper(args).getOr(0, "%s"), remainDur)
+ }
+ return argsHelper(args).getOr(2, "?")
+}
+
+// ElementElapsedTime shows elapsed time
+// Optionally can take one argument - it's format for time string.
+// In template use as follows: {{etime .}} or {{etime . "%s elapsed"}}
+var ElementElapsedTime ElementFunc = func(state *State, args ...string) string {
+ return fmt.Sprintf(argsHelper(args).getOr(0, "%s"), elapsedTime(state))
+}
+
+// ElementString get value from bar by given key and print them
+// bar.Set("myKey", "string to print")
+// In template use as follows: {{string . "myKey"}}
+var ElementString ElementFunc = func(state *State, args ...string) string {
+ if len(args) == 0 {
+ return ""
+ }
+ v := state.Get(args[0])
+ if v == nil {
+ return ""
+ }
+ return fmt.Sprint(v)
+}
+
+// ElementCycle return next argument for every call
+// In template use as follows: {{cycle . "1" "2" "3"}}
+// Or mix width other elements: {{ bar . "" "" (cycle . "↖" "↗" "↘" "↙" )}}
+var ElementCycle ElementFunc = func(state *State, args ...string) string {
+ if len(args) == 0 {
+ return ""
+ }
+ n, _ := state.Get(cycleObj).(int)
+ if n >= len(args) {
+ n = 0
+ }
+ state.Set(cycleObj, n+1)
+ return args[n]
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/io.go b/vendor/github.com/cheggaaa/pb/v3/io.go
new file mode 100644
index 0000000..6ad5abc
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/io.go
@@ -0,0 +1,49 @@
+package pb
+
+import (
+ "io"
+)
+
+// Reader it's a wrapper for given reader, but with progress handle
+type Reader struct {
+ io.Reader
+ bar *ProgressBar
+}
+
+// Read reads bytes from wrapped reader and add amount of bytes to progress bar
+func (r *Reader) Read(p []byte) (n int, err error) {
+ n, err = r.Reader.Read(p)
+ r.bar.Add(n)
+ return
+}
+
+// Close the wrapped reader when it implements io.Closer
+func (r *Reader) Close() (err error) {
+ r.bar.Finish()
+ if closer, ok := r.Reader.(io.Closer); ok {
+ return closer.Close()
+ }
+ return
+}
+
+// Writer it's a wrapper for given writer, but with progress handle
+type Writer struct {
+ io.Writer
+ bar *ProgressBar
+}
+
+// Write writes bytes to wrapped writer and add amount of bytes to progress bar
+func (r *Writer) Write(p []byte) (n int, err error) {
+ n, err = r.Writer.Write(p)
+ r.bar.Add(n)
+ return
+}
+
+// Close the wrapped reader when it implements io.Closer
+func (r *Writer) Close() (err error) {
+ r.bar.Finish()
+ if closer, ok := r.Writer.(io.Closer); ok {
+ return closer.Close()
+ }
+ return
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/pb.go b/vendor/github.com/cheggaaa/pb/v3/pb.go
new file mode 100644
index 0000000..76440e1
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/pb.go
@@ -0,0 +1,595 @@
+package pb
+
+import (
+ "bytes"
+ "fmt"
+ "io"
+ "os"
+ "strconv"
+ "strings"
+ "sync"
+ "sync/atomic"
+ "text/template"
+ "time"
+
+ "github.com/fatih/color"
+
+ "github.com/mattn/go-colorable"
+ "github.com/mattn/go-isatty"
+
+ "github.com/cheggaaa/pb/v3/termutil"
+)
+
+// Version of ProgressBar library
+const Version = "3.0.8"
+
+type key int
+
+const (
+ // Bytes means we're working with byte sizes. Numbers will print as Kb, Mb, etc
+ // bar.Set(pb.Bytes, true)
+ Bytes key = 1 << iota
+
+ // Use SI bytes prefix names (kB, MB, etc) instead of IEC prefix names (KiB, MiB, etc)
+ SIBytesPrefix
+
+ // Terminal means we're will print to terminal and can use ascii sequences
+ // Also we're will try to use terminal width
+ Terminal
+
+ // Static means progress bar will not update automaticly
+ Static
+
+ // ReturnSymbol - by default in terminal mode it's '\r'
+ ReturnSymbol
+
+ // Color by default is true when output is tty, but you can set to false for disabling colors
+ Color
+
+ // Hide the progress bar when finished, rather than leaving it up. By default it's false.
+ CleanOnFinish
+
+ // Round elapsed time to this precision. Defaults to time.Second.
+ TimeRound
+)
+
+const (
+ defaultBarWidth = 100
+ defaultRefreshRate = time.Millisecond * 200
+)
+
+// New creates new ProgressBar object
+func New(total int) *ProgressBar {
+ return New64(int64(total))
+}
+
+// New64 creates new ProgressBar object using int64 as total
+func New64(total int64) *ProgressBar {
+ pb := new(ProgressBar)
+ return pb.SetTotal(total)
+}
+
+// StartNew starts new ProgressBar with Default template
+func StartNew(total int) *ProgressBar {
+ return New(total).Start()
+}
+
+// Start64 starts new ProgressBar with Default template. Using int64 as total.
+func Start64(total int64) *ProgressBar {
+ return New64(total).Start()
+}
+
+var (
+ terminalWidth = termutil.TerminalWidth
+ isTerminal = isatty.IsTerminal
+ isCygwinTerminal = isatty.IsCygwinTerminal
+)
+
+// ProgressBar is the main object of bar
+type ProgressBar struct {
+ current, total int64
+ width int
+ maxWidth int
+ mu sync.RWMutex
+ rm sync.Mutex
+ vars map[interface{}]interface{}
+ elements map[string]Element
+ output io.Writer
+ coutput io.Writer
+ nocoutput io.Writer
+ startTime time.Time
+ refreshRate time.Duration
+ tmpl *template.Template
+ state *State
+ buf *bytes.Buffer
+ ticker *time.Ticker
+ finish chan struct{}
+ finished bool
+ configured bool
+ err error
+}
+
+func (pb *ProgressBar) configure() {
+ if pb.configured {
+ return
+ }
+ pb.configured = true
+
+ if pb.vars == nil {
+ pb.vars = make(map[interface{}]interface{})
+ }
+ if pb.output == nil {
+ pb.output = os.Stderr
+ }
+
+ if pb.tmpl == nil {
+ pb.tmpl, pb.err = getTemplate(string(Default))
+ if pb.err != nil {
+ return
+ }
+ }
+ if pb.vars[Terminal] == nil {
+ if f, ok := pb.output.(*os.File); ok {
+ if isTerminal(f.Fd()) || isCygwinTerminal(f.Fd()) {
+ pb.vars[Terminal] = true
+ }
+ }
+ }
+ if pb.vars[ReturnSymbol] == nil {
+ if tm, ok := pb.vars[Terminal].(bool); ok && tm {
+ pb.vars[ReturnSymbol] = "\r"
+ }
+ }
+ if pb.vars[Color] == nil {
+ if tm, ok := pb.vars[Terminal].(bool); ok && tm {
+ pb.vars[Color] = true
+ }
+ }
+ if pb.refreshRate == 0 {
+ pb.refreshRate = defaultRefreshRate
+ }
+ if pb.vars[CleanOnFinish] == nil {
+ pb.vars[CleanOnFinish] = false
+ }
+ if f, ok := pb.output.(*os.File); ok {
+ pb.coutput = colorable.NewColorable(f)
+ } else {
+ pb.coutput = pb.output
+ }
+ pb.nocoutput = colorable.NewNonColorable(pb.output)
+}
+
+// Start starts the bar
+func (pb *ProgressBar) Start() *ProgressBar {
+ pb.mu.Lock()
+ defer pb.mu.Unlock()
+ if pb.finish != nil {
+ return pb
+ }
+ pb.configure()
+ pb.finished = false
+ pb.state = nil
+ pb.startTime = time.Now()
+ if st, ok := pb.vars[Static].(bool); ok && st {
+ return pb
+ }
+ pb.finish = make(chan struct{})
+ pb.ticker = time.NewTicker(pb.refreshRate)
+ go pb.writer(pb.finish)
+ return pb
+}
+
+func (pb *ProgressBar) writer(finish chan struct{}) {
+ for {
+ select {
+ case <-pb.ticker.C:
+ pb.write(false)
+ case <-finish:
+ pb.ticker.Stop()
+ pb.write(true)
+ finish <- struct{}{}
+ return
+ }
+ }
+}
+
+// Write performs write to the output
+func (pb *ProgressBar) Write() *ProgressBar {
+ pb.mu.RLock()
+ finished := pb.finished
+ pb.mu.RUnlock()
+ pb.write(finished)
+ return pb
+}
+
+func (pb *ProgressBar) write(finish bool) {
+ result, width := pb.render()
+ if pb.Err() != nil {
+ return
+ }
+ if pb.GetBool(Terminal) {
+ if r := (width - CellCount(result)); r > 0 {
+ result += strings.Repeat(" ", r)
+ }
+ }
+ if ret, ok := pb.Get(ReturnSymbol).(string); ok {
+ result = ret + result
+ if finish && ret == "\r" {
+ if pb.GetBool(CleanOnFinish) {
+ // "Wipe out" progress bar by overwriting one line with blanks
+ result = "\r" + color.New(color.Reset).Sprintf(strings.Repeat(" ", width)) + "\r"
+ } else {
+ result += "\n"
+ }
+ }
+ }
+ if pb.GetBool(Color) {
+ pb.coutput.Write([]byte(result))
+ } else {
+ pb.nocoutput.Write([]byte(result))
+ }
+}
+
+// Total return current total bar value
+func (pb *ProgressBar) Total() int64 {
+ return atomic.LoadInt64(&pb.total)
+}
+
+// SetTotal sets the total bar value
+func (pb *ProgressBar) SetTotal(value int64) *ProgressBar {
+ atomic.StoreInt64(&pb.total, value)
+ return pb
+}
+
+// AddTotal adds to the total bar value
+func (pb *ProgressBar) AddTotal(value int64) *ProgressBar {
+ atomic.AddInt64(&pb.total, value)
+ return pb
+}
+
+// SetCurrent sets the current bar value
+func (pb *ProgressBar) SetCurrent(value int64) *ProgressBar {
+ atomic.StoreInt64(&pb.current, value)
+ return pb
+}
+
+// Current return current bar value
+func (pb *ProgressBar) Current() int64 {
+ return atomic.LoadInt64(&pb.current)
+}
+
+// Add adding given int64 value to bar value
+func (pb *ProgressBar) Add64(value int64) *ProgressBar {
+ atomic.AddInt64(&pb.current, value)
+ return pb
+}
+
+// Add adding given int value to bar value
+func (pb *ProgressBar) Add(value int) *ProgressBar {
+ return pb.Add64(int64(value))
+}
+
+// Increment atomically increments the progress
+func (pb *ProgressBar) Increment() *ProgressBar {
+ return pb.Add64(1)
+}
+
+// Set sets any value by any key
+func (pb *ProgressBar) Set(key, value interface{}) *ProgressBar {
+ pb.mu.Lock()
+ defer pb.mu.Unlock()
+ if pb.vars == nil {
+ pb.vars = make(map[interface{}]interface{})
+ }
+ pb.vars[key] = value
+ return pb
+}
+
+// Get return value by key
+func (pb *ProgressBar) Get(key interface{}) interface{} {
+ pb.mu.RLock()
+ defer pb.mu.RUnlock()
+ if pb.vars == nil {
+ return nil
+ }
+ return pb.vars[key]
+}
+
+// GetBool return value by key and try to convert there to boolean
+// If value doesn't set or not boolean - return false
+func (pb *ProgressBar) GetBool(key interface{}) bool {
+ if v, ok := pb.Get(key).(bool); ok {
+ return v
+ }
+ return false
+}
+
+// SetWidth sets the bar width
+// When given value <= 0 would be using the terminal width (if possible) or default value.
+func (pb *ProgressBar) SetWidth(width int) *ProgressBar {
+ pb.mu.Lock()
+ pb.width = width
+ pb.mu.Unlock()
+ return pb
+}
+
+// SetMaxWidth sets the bar maximum width
+// When given value <= 0 would be using the terminal width (if possible) or default value.
+func (pb *ProgressBar) SetMaxWidth(maxWidth int) *ProgressBar {
+ pb.mu.Lock()
+ pb.maxWidth = maxWidth
+ pb.mu.Unlock()
+ return pb
+}
+
+// Width return the bar width
+// It's current terminal width or settled over 'SetWidth' value.
+func (pb *ProgressBar) Width() (width int) {
+ defer func() {
+ if r := recover(); r != nil {
+ width = defaultBarWidth
+ }
+ }()
+ pb.mu.RLock()
+ width = pb.width
+ maxWidth := pb.maxWidth
+ pb.mu.RUnlock()
+ if width <= 0 {
+ var err error
+ if width, err = terminalWidth(); err != nil {
+ return defaultBarWidth
+ }
+ }
+ if maxWidth > 0 && width > maxWidth {
+ width = maxWidth
+ }
+ return
+}
+
+func (pb *ProgressBar) SetRefreshRate(dur time.Duration) *ProgressBar {
+ pb.mu.Lock()
+ if dur > 0 {
+ pb.refreshRate = dur
+ }
+ pb.mu.Unlock()
+ return pb
+}
+
+// SetWriter sets the io.Writer. Bar will write in this writer
+// By default this is os.Stderr
+func (pb *ProgressBar) SetWriter(w io.Writer) *ProgressBar {
+ pb.mu.Lock()
+ pb.output = w
+ pb.configured = false
+ pb.configure()
+ pb.mu.Unlock()
+ return pb
+}
+
+// StartTime return the time when bar started
+func (pb *ProgressBar) StartTime() time.Time {
+ pb.mu.RLock()
+ defer pb.mu.RUnlock()
+ return pb.startTime
+}
+
+// Format convert int64 to string according to the current settings
+func (pb *ProgressBar) Format(v int64) string {
+ if pb.GetBool(Bytes) {
+ return formatBytes(v, pb.GetBool(SIBytesPrefix))
+ }
+ return strconv.FormatInt(v, 10)
+}
+
+// Finish stops the bar
+func (pb *ProgressBar) Finish() *ProgressBar {
+ pb.mu.Lock()
+ if pb.finished {
+ pb.mu.Unlock()
+ return pb
+ }
+ finishChan := pb.finish
+ pb.finished = true
+ pb.mu.Unlock()
+ if finishChan != nil {
+ finishChan <- struct{}{}
+ <-finishChan
+ pb.mu.Lock()
+ pb.finish = nil
+ pb.mu.Unlock()
+ }
+ return pb
+}
+
+// IsStarted indicates progress bar state
+func (pb *ProgressBar) IsStarted() bool {
+ pb.mu.RLock()
+ defer pb.mu.RUnlock()
+ return pb.finish != nil
+}
+
+// IsFinished indicates progress bar is finished
+func (pb *ProgressBar) IsFinished() bool {
+ pb.mu.RLock()
+ defer pb.mu.RUnlock()
+ return pb.finished
+}
+
+// SetTemplateString sets ProgressBar tempate string and parse it
+func (pb *ProgressBar) SetTemplateString(tmpl string) *ProgressBar {
+ pb.mu.Lock()
+ defer pb.mu.Unlock()
+ pb.tmpl, pb.err = getTemplate(tmpl)
+ return pb
+}
+
+// SetTemplateString sets ProgressBarTempate and parse it
+func (pb *ProgressBar) SetTemplate(tmpl ProgressBarTemplate) *ProgressBar {
+ return pb.SetTemplateString(string(tmpl))
+}
+
+// NewProxyReader creates a wrapper for given reader, but with progress handle
+// Takes io.Reader or io.ReadCloser
+// Also, it automatically switches progress bar to handle units as bytes
+func (pb *ProgressBar) NewProxyReader(r io.Reader) *Reader {
+ pb.Set(Bytes, true)
+ return &Reader{r, pb}
+}
+
+// NewProxyWriter creates a wrapper for given writer, but with progress handle
+// Takes io.Writer or io.WriteCloser
+// Also, it automatically switches progress bar to handle units as bytes
+func (pb *ProgressBar) NewProxyWriter(r io.Writer) *Writer {
+ pb.Set(Bytes, true)
+ return &Writer{r, pb}
+}
+
+func (pb *ProgressBar) render() (result string, width int) {
+ defer func() {
+ if r := recover(); r != nil {
+ pb.SetErr(fmt.Errorf("render panic: %v", r))
+ }
+ }()
+ pb.rm.Lock()
+ defer pb.rm.Unlock()
+ pb.mu.Lock()
+ pb.configure()
+ if pb.state == nil {
+ pb.state = &State{ProgressBar: pb}
+ pb.buf = bytes.NewBuffer(nil)
+ }
+ if pb.startTime.IsZero() {
+ pb.startTime = time.Now()
+ }
+ pb.state.id++
+ pb.state.finished = pb.finished
+ pb.state.time = time.Now()
+ pb.mu.Unlock()
+
+ pb.state.width = pb.Width()
+ width = pb.state.width
+ pb.state.total = pb.Total()
+ pb.state.current = pb.Current()
+ pb.buf.Reset()
+
+ if e := pb.tmpl.Execute(pb.buf, pb.state); e != nil {
+ pb.SetErr(e)
+ return "", 0
+ }
+
+ result = pb.buf.String()
+
+ aec := len(pb.state.recalc)
+ if aec == 0 {
+ // no adaptive elements
+ return
+ }
+
+ staticWidth := CellCount(result) - (aec * adElPlaceholderLen)
+
+ if pb.state.Width()-staticWidth <= 0 {
+ result = strings.Replace(result, adElPlaceholder, "", -1)
+ result = StripString(result, pb.state.Width())
+ } else {
+ pb.state.adaptiveElWidth = (width - staticWidth) / aec
+ for _, el := range pb.state.recalc {
+ result = strings.Replace(result, adElPlaceholder, el.ProgressElement(pb.state), 1)
+ }
+ }
+ pb.state.recalc = pb.state.recalc[:0]
+ return
+}
+
+// SetErr sets error to the ProgressBar
+// Error will be available over Err()
+func (pb *ProgressBar) SetErr(err error) *ProgressBar {
+ pb.mu.Lock()
+ pb.err = err
+ pb.mu.Unlock()
+ return pb
+}
+
+// Err return possible error
+// When all ok - will be nil
+// May contain template.Execute errors
+func (pb *ProgressBar) Err() error {
+ pb.mu.RLock()
+ defer pb.mu.RUnlock()
+ return pb.err
+}
+
+// String return currrent string representation of ProgressBar
+func (pb *ProgressBar) String() string {
+ res, _ := pb.render()
+ return res
+}
+
+// ProgressElement implements Element interface
+func (pb *ProgressBar) ProgressElement(s *State, args ...string) string {
+ if s.IsAdaptiveWidth() {
+ pb.SetWidth(s.AdaptiveElWidth())
+ }
+ return pb.String()
+}
+
+// State represents the current state of bar
+// Need for bar elements
+type State struct {
+ *ProgressBar
+
+ id uint64
+ total, current int64
+ width, adaptiveElWidth int
+ finished, adaptive bool
+ time time.Time
+
+ recalc []Element
+}
+
+// Id it's the current state identifier
+// - incremental
+// - starts with 1
+// - resets after finish/start
+func (s *State) Id() uint64 {
+ return s.id
+}
+
+// Total it's bar int64 total
+func (s *State) Total() int64 {
+ return s.total
+}
+
+// Value it's current value
+func (s *State) Value() int64 {
+ return s.current
+}
+
+// Width of bar
+func (s *State) Width() int {
+ return s.width
+}
+
+// AdaptiveElWidth - adaptive elements must return string with given cell count (when AdaptiveElWidth > 0)
+func (s *State) AdaptiveElWidth() int {
+ return s.adaptiveElWidth
+}
+
+// IsAdaptiveWidth returns true when element must be shown as adaptive
+func (s *State) IsAdaptiveWidth() bool {
+ return s.adaptive
+}
+
+// IsFinished return true when bar is finished
+func (s *State) IsFinished() bool {
+ return s.finished
+}
+
+// IsFirst return true only in first render
+func (s *State) IsFirst() bool {
+ return s.id == 1
+}
+
+// Time when state was created
+func (s *State) Time() time.Time {
+ return s.time
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/pool.go b/vendor/github.com/cheggaaa/pb/v3/pool.go
new file mode 100644
index 0000000..69cc825
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/pool.go
@@ -0,0 +1,105 @@
+// +build linux darwin freebsd netbsd openbsd solaris dragonfly windows plan9 aix
+
+package pb
+
+import (
+ "io"
+ "sync"
+ "time"
+
+ "github.com/cheggaaa/pb/v3/termutil"
+)
+
+// Create and start new pool with given bars
+// You need call pool.Stop() after work
+func StartPool(pbs ...*ProgressBar) (pool *Pool, err error) {
+ pool = new(Pool)
+ if err = pool.Start(); err != nil {
+ return
+ }
+ pool.Add(pbs...)
+ return
+}
+
+// NewPool initialises a pool with progress bars, but
+// doesn't start it. You need to call Start manually
+func NewPool(pbs ...*ProgressBar) (pool *Pool) {
+ pool = new(Pool)
+ pool.Add(pbs...)
+ return
+}
+
+type Pool struct {
+ Output io.Writer
+ RefreshRate time.Duration
+ bars []*ProgressBar
+ lastBarsCount int
+ shutdownCh chan struct{}
+ workerCh chan struct{}
+ m sync.Mutex
+ finishOnce sync.Once
+}
+
+// Add progress bars.
+func (p *Pool) Add(pbs ...*ProgressBar) {
+ p.m.Lock()
+ defer p.m.Unlock()
+ for _, bar := range pbs {
+ bar.Set(Static, true)
+ bar.Start()
+ p.bars = append(p.bars, bar)
+ }
+}
+
+func (p *Pool) Start() (err error) {
+ p.RefreshRate = defaultRefreshRate
+ p.shutdownCh, err = termutil.RawModeOn()
+ if err != nil {
+ return
+ }
+ p.workerCh = make(chan struct{})
+ go p.writer()
+ return
+}
+
+func (p *Pool) writer() {
+ var first = true
+ defer func() {
+ if first == false {
+ p.print(false)
+ } else {
+ p.print(true)
+ p.print(false)
+ }
+ close(p.workerCh)
+ }()
+
+ for {
+ select {
+ case <-time.After(p.RefreshRate):
+ if p.print(first) {
+ p.print(false)
+ return
+ }
+ first = false
+ case <-p.shutdownCh:
+ return
+ }
+ }
+}
+
+// Restore terminal state and close pool
+func (p *Pool) Stop() error {
+ p.finishOnce.Do(func() {
+ if p.shutdownCh != nil {
+ close(p.shutdownCh)
+ }
+ })
+
+ // Wait for the worker to complete
+ select {
+ case <-p.workerCh:
+ }
+
+ return termutil.RawModeOff()
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/pool_win.go b/vendor/github.com/cheggaaa/pb/v3/pool_win.go
new file mode 100644
index 0000000..7002e85
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/pool_win.go
@@ -0,0 +1,56 @@
+//go:build windows
+// +build windows
+
+package pb
+
+import (
+ "fmt"
+ "log"
+ "strings"
+
+ "github.com/cheggaaa/pb/v3/termutil"
+)
+
+func (p *Pool) print(first bool) bool {
+ p.m.Lock()
+ defer p.m.Unlock()
+ var out string
+ if !first {
+ coords, err := termutil.GetCursorPos()
+ if err != nil {
+ log.Panic(err)
+ }
+ coords.Y -= int16(p.lastBarsCount)
+ if coords.Y < 0 {
+ coords.Y = 0
+ }
+ coords.X = 0
+
+ err = termutil.SetCursorPos(coords)
+ if err != nil {
+ log.Panic(err)
+ }
+ }
+ cols, err := termutil.TerminalWidth()
+ if err != nil {
+ cols = defaultBarWidth
+ }
+ isFinished := true
+ for _, bar := range p.bars {
+ if !bar.IsFinished() {
+ isFinished = false
+ }
+ result := bar.String()
+ if r := cols - CellCount(result); r > 0 {
+ result += strings.Repeat(" ", r)
+ }
+ out += fmt.Sprintf("\r%s\n", result)
+ }
+ if p.Output != nil {
+ fmt.Fprint(p.Output, out)
+ } else {
+ fmt.Print(out)
+ }
+ p.lastBarsCount = len(p.bars)
+ return isFinished
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/pool_x.go b/vendor/github.com/cheggaaa/pb/v3/pool_x.go
new file mode 100644
index 0000000..cae9758
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/pool_x.go
@@ -0,0 +1,49 @@
+//go:build linux || darwin || freebsd || netbsd || openbsd || solaris || dragonfly || plan9 || aix
+// +build linux darwin freebsd netbsd openbsd solaris dragonfly plan9 aix
+
+package pb
+
+import (
+ "fmt"
+ "os"
+ "strings"
+
+ "github.com/cheggaaa/pb/v3/termutil"
+)
+
+func (p *Pool) print(first bool) bool {
+ p.m.Lock()
+ defer p.m.Unlock()
+ var out string
+ if !first {
+ out = fmt.Sprintf("\033[%dA", p.lastBarsCount)
+ }
+ isFinished := true
+ bars := p.bars
+ rows, cols, err := termutil.TerminalSize()
+ if err != nil {
+ cols = defaultBarWidth
+ }
+ if rows > 0 && len(bars) > rows {
+ // we need to hide bars that overflow terminal height
+ bars = bars[len(bars)-rows:]
+ }
+ for _, bar := range bars {
+ if !bar.IsFinished() {
+ isFinished = false
+ }
+ bar.SetWidth(cols)
+ result := bar.String()
+ if r := cols - CellCount(result); r > 0 {
+ result += strings.Repeat(" ", r)
+ }
+ out += fmt.Sprintf("\r%s\n", result)
+ }
+ if p.Output != nil {
+ fmt.Fprint(p.Output, out)
+ } else {
+ fmt.Fprint(os.Stderr, out)
+ }
+ p.lastBarsCount = len(bars)
+ return isFinished
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/preset.go b/vendor/github.com/cheggaaa/pb/v3/preset.go
new file mode 100644
index 0000000..f3ca193
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/preset.go
@@ -0,0 +1,15 @@
+package pb
+
+var (
+ // Full - preset with all default available elements
+ // Example: 'Prefix 20/100 [-->______] 20% 1 p/s ETA 1m Suffix'
+ Full ProgressBarTemplate = `{{with string . "prefix"}}{{.}} {{end}}{{counters . }} {{bar . }} {{percent . }} {{speed . }} {{rtime . "ETA %s"}}{{with string . "suffix"}} {{.}}{{end}}`
+
+ // Default - preset like Full but without elapsed time
+ // Example: 'Prefix 20/100 [-->______] 20% 1 p/s Suffix'
+ Default ProgressBarTemplate = `{{with string . "prefix"}}{{.}} {{end}}{{counters . }} {{bar . }} {{percent . }} {{speed . }}{{with string . "suffix"}} {{.}}{{end}}`
+
+ // Simple - preset without speed and any timers. Only counters, bar and percents
+ // Example: 'Prefix 20/100 [-->______] 20% Suffix'
+ Simple ProgressBarTemplate = `{{with string . "prefix"}}{{.}} {{end}}{{counters . }} {{bar . }} {{percent . }}{{with string . "suffix"}} {{.}}{{end}}`
+)
diff --git a/vendor/github.com/cheggaaa/pb/v3/speed.go b/vendor/github.com/cheggaaa/pb/v3/speed.go
new file mode 100644
index 0000000..17a6b1b
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/speed.go
@@ -0,0 +1,83 @@
+package pb
+
+import (
+ "fmt"
+ "math"
+ "time"
+
+ "github.com/VividCortex/ewma"
+)
+
+var speedAddLimit = time.Second / 2
+
+type speed struct {
+ ewma ewma.MovingAverage
+ lastStateId uint64
+ prevValue, startValue int64
+ prevTime, startTime time.Time
+}
+
+func (s *speed) value(state *State) float64 {
+ if s.ewma == nil {
+ s.ewma = ewma.NewMovingAverage()
+ }
+ if state.IsFirst() || state.Id() < s.lastStateId {
+ s.reset(state)
+ return 0
+ }
+ if state.Id() == s.lastStateId {
+ return s.ewma.Value()
+ }
+ if state.IsFinished() {
+ return s.absValue(state)
+ }
+ dur := state.Time().Sub(s.prevTime)
+ if dur < speedAddLimit {
+ return s.ewma.Value()
+ }
+ diff := math.Abs(float64(state.Value() - s.prevValue))
+ lastSpeed := diff / dur.Seconds()
+ s.prevTime = state.Time()
+ s.prevValue = state.Value()
+ s.lastStateId = state.Id()
+ s.ewma.Add(lastSpeed)
+ return s.ewma.Value()
+}
+
+func (s *speed) reset(state *State) {
+ s.lastStateId = state.Id()
+ s.startTime = state.Time()
+ s.prevTime = state.Time()
+ s.startValue = state.Value()
+ s.prevValue = state.Value()
+ s.ewma = ewma.NewMovingAverage()
+}
+
+func (s *speed) absValue(state *State) float64 {
+ if dur := state.Time().Sub(s.startTime); dur > 0 {
+ return float64(state.Value()) / dur.Seconds()
+ }
+ return 0
+}
+
+func getSpeedObj(state *State) (s *speed) {
+ if sObj, ok := state.Get(speedObj).(*speed); ok {
+ return sObj
+ }
+ s = new(speed)
+ state.Set(speedObj, s)
+ return
+}
+
+// ElementSpeed calculates current speed by EWMA
+// Optionally can take one or two string arguments.
+// First string will be used as value for format speed, default is "%s p/s".
+// Second string will be used when speed not available, default is "? p/s"
+// In template use as follows: {{speed .}} or {{speed . "%s per second"}} or {{speed . "%s ps" "..."}
+var ElementSpeed ElementFunc = func(state *State, args ...string) string {
+ sp := getSpeedObj(state).value(state)
+ if sp == 0 {
+ return argsHelper(args).getNotEmptyOr(1, "? p/s")
+ }
+ return fmt.Sprintf(argsHelper(args).getNotEmptyOr(0, "%s p/s"), state.Format(int64(round(sp))))
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/template.go b/vendor/github.com/cheggaaa/pb/v3/template.go
new file mode 100644
index 0000000..5272ac1
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/template.go
@@ -0,0 +1,89 @@
+package pb
+
+import (
+ "math/rand"
+ "sync"
+ "text/template"
+
+ "github.com/fatih/color"
+)
+
+// ProgressBarTemplate that template string
+type ProgressBarTemplate string
+
+// New creates new bar from template
+func (pbt ProgressBarTemplate) New(total int) *ProgressBar {
+ return New(total).SetTemplate(pbt)
+}
+
+// Start64 create and start new bar with given int64 total value
+func (pbt ProgressBarTemplate) Start64(total int64) *ProgressBar {
+ return New64(total).SetTemplate(pbt).Start()
+}
+
+// Start create and start new bar with given int total value
+func (pbt ProgressBarTemplate) Start(total int) *ProgressBar {
+ return pbt.Start64(int64(total))
+}
+
+var templateCacheMu sync.Mutex
+var templateCache = make(map[string]*template.Template)
+
+var defaultTemplateFuncs = template.FuncMap{
+ // colors
+ "black": color.New(color.FgBlack).SprintFunc(),
+ "red": color.New(color.FgRed).SprintFunc(),
+ "green": color.New(color.FgGreen).SprintFunc(),
+ "yellow": color.New(color.FgYellow).SprintFunc(),
+ "blue": color.New(color.FgBlue).SprintFunc(),
+ "magenta": color.New(color.FgMagenta).SprintFunc(),
+ "cyan": color.New(color.FgCyan).SprintFunc(),
+ "white": color.New(color.FgWhite).SprintFunc(),
+ "resetcolor": color.New(color.Reset).SprintFunc(),
+ "rndcolor": rndcolor,
+ "rnd": rnd,
+}
+
+func getTemplate(tmpl string) (t *template.Template, err error) {
+ templateCacheMu.Lock()
+ defer templateCacheMu.Unlock()
+ t = templateCache[tmpl]
+ if t != nil {
+ // found in cache
+ return
+ }
+ t = template.New("")
+ fillTemplateFuncs(t)
+ _, err = t.Parse(tmpl)
+ if err != nil {
+ t = nil
+ return
+ }
+ templateCache[tmpl] = t
+ return
+}
+
+func fillTemplateFuncs(t *template.Template) {
+ t.Funcs(defaultTemplateFuncs)
+ emf := make(template.FuncMap)
+ elementsM.Lock()
+ for k, v := range elements {
+ element := v
+ emf[k] = func(state *State, args ...string) string { return element.ProgressElement(state, args...) }
+ }
+ elementsM.Unlock()
+ t.Funcs(emf)
+ return
+}
+
+func rndcolor(s string) string {
+ c := rand.Intn(int(color.FgWhite-color.FgBlack)) + int(color.FgBlack)
+ return color.New(color.Attribute(c)).Sprint(s)
+}
+
+func rnd(args ...string) string {
+ if len(args) == 0 {
+ return ""
+ }
+ return args[rand.Intn(len(args))]
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/termutil/term.go b/vendor/github.com/cheggaaa/pb/v3/termutil/term.go
new file mode 100644
index 0000000..c838d4f
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/termutil/term.go
@@ -0,0 +1,68 @@
+package termutil
+
+import (
+ "errors"
+ "os"
+ "os/signal"
+ "sync"
+)
+
+var echoLocked bool
+var echoLockMutex sync.Mutex
+var errLocked = errors.New("terminal locked")
+var autoTerminate = true
+
+// AutoTerminate enables or disables automatic terminate signal catching.
+// It's needed to restore the terminal state after the pool was used.
+// By default, it's enabled.
+func AutoTerminate(enable bool) {
+ echoLockMutex.Lock()
+ defer echoLockMutex.Unlock()
+ autoTerminate = enable
+}
+
+// RawModeOn switches terminal to raw mode
+func RawModeOn() (quit chan struct{}, err error) {
+ echoLockMutex.Lock()
+ defer echoLockMutex.Unlock()
+ if echoLocked {
+ err = errLocked
+ return
+ }
+ if err = lockEcho(); err != nil {
+ return
+ }
+ echoLocked = true
+ quit = make(chan struct{}, 1)
+ go catchTerminate(quit)
+ return
+}
+
+// RawModeOff restore previous terminal state
+func RawModeOff() (err error) {
+ echoLockMutex.Lock()
+ defer echoLockMutex.Unlock()
+ if !echoLocked {
+ return
+ }
+ if err = unlockEcho(); err != nil {
+ return
+ }
+ echoLocked = false
+ return
+}
+
+// listen exit signals and restore terminal state
+func catchTerminate(quit chan struct{}) {
+ sig := make(chan os.Signal, 1)
+ if autoTerminate {
+ signal.Notify(sig, unlockSignals...)
+ defer signal.Stop(sig)
+ }
+ select {
+ case <-quit:
+ RawModeOff()
+ case <-sig:
+ RawModeOff()
+ }
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/termutil/term_aix.go b/vendor/github.com/cheggaaa/pb/v3/termutil/term_aix.go
new file mode 100644
index 0000000..5bbc5ef
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/termutil/term_aix.go
@@ -0,0 +1,69 @@
+//go:build aix
+
+package termutil
+
+import (
+ "os"
+ "syscall"
+
+ "golang.org/x/sys/unix"
+)
+
+var (
+ tty *os.File
+
+ unlockSignals = []os.Signal{
+ os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL,
+ }
+)
+
+func init() {
+ var err error
+ tty, err = os.Open("/dev/tty")
+ if err != nil {
+ tty = os.Stdin
+ }
+}
+
+// TerminalWidth returns width of the terminal.
+func TerminalWidth() (int, error) {
+ _, width, err := TerminalSize()
+ return width, err
+}
+
+// TerminalSize returns size of the terminal.
+func TerminalSize() (int, int, error) {
+ w, err := unix.IoctlGetWinsize(int(tty.Fd()), syscall.TIOCGWINSZ)
+ if err != nil {
+ return 0, 0, err
+ }
+ return int(w.Row), int(w.Col), nil
+}
+
+var oldState unix.Termios
+
+func lockEcho() error {
+ fd := int(tty.Fd())
+ currentState, err := unix.IoctlGetTermios(fd, unix.TCGETS)
+ if err != nil {
+ return err
+ }
+
+ oldState = *currentState
+ newState := oldState
+ newState.Lflag &^= syscall.ECHO
+ newState.Lflag |= syscall.ICANON | syscall.ISIG
+ newState.Iflag |= syscall.ICRNL
+ if err := unix.IoctlSetTermios(fd, unix.TCSETS, &newState); err != nil {
+ return err
+ }
+ return nil
+}
+
+func unlockEcho() (err error) {
+ fd := int(tty.Fd())
+ if err := unix.IoctlSetTermios(fd, unix.TCSETS, &oldState); err != nil {
+ return err
+ }
+ return
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/termutil/term_appengine.go b/vendor/github.com/cheggaaa/pb/v3/termutil/term_appengine.go
new file mode 100644
index 0000000..6bc5c51
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/termutil/term_appengine.go
@@ -0,0 +1,12 @@
+//go:build appengine
+// +build appengine
+
+package termutil
+
+import "errors"
+
+// terminalWidth returns width of the terminal, which is not supported
+// and should always failed on appengine classic which is a sandboxed PaaS.
+func TerminalWidth() (int, error) {
+ return 0, errors.New("Not supported")
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/termutil/term_bsd.go b/vendor/github.com/cheggaaa/pb/v3/termutil/term_bsd.go
new file mode 100644
index 0000000..e16380f
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/termutil/term_bsd.go
@@ -0,0 +1,10 @@
+//go:build (darwin || freebsd || netbsd || openbsd || dragonfly) && !appengine
+// +build darwin freebsd netbsd openbsd dragonfly
+// +build !appengine
+
+package termutil
+
+import "syscall"
+
+const ioctlReadTermios = syscall.TIOCGETA
+const ioctlWriteTermios = syscall.TIOCSETA
diff --git a/vendor/github.com/cheggaaa/pb/v3/termutil/term_linux.go b/vendor/github.com/cheggaaa/pb/v3/termutil/term_linux.go
new file mode 100644
index 0000000..f4c5325
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/termutil/term_linux.go
@@ -0,0 +1,7 @@
+//go:build linux && !appengine
+// +build linux,!appengine
+
+package termutil
+
+const ioctlReadTermios = 0x5401 // syscall.TCGETS
+const ioctlWriteTermios = 0x5402 // syscall.TCSETS
diff --git a/vendor/github.com/cheggaaa/pb/v3/termutil/term_nix.go b/vendor/github.com/cheggaaa/pb/v3/termutil/term_nix.go
new file mode 100644
index 0000000..471d5a9
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/termutil/term_nix.go
@@ -0,0 +1,9 @@
+//go:build (linux || darwin || freebsd || netbsd || openbsd || dragonfly) && !appengine
+// +build linux darwin freebsd netbsd openbsd dragonfly
+// +build !appengine
+
+package termutil
+
+import "syscall"
+
+const sysIoctl = syscall.SYS_IOCTL
diff --git a/vendor/github.com/cheggaaa/pb/v3/termutil/term_plan9.go b/vendor/github.com/cheggaaa/pb/v3/termutil/term_plan9.go
new file mode 100644
index 0000000..f3934c6
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/termutil/term_plan9.go
@@ -0,0 +1,50 @@
+package termutil
+
+import (
+ "errors"
+ "os"
+ "syscall"
+)
+
+var (
+ consctl *os.File
+
+ // Plan 9 doesn't have syscall.SIGQUIT
+ unlockSignals = []os.Signal{
+ os.Interrupt, syscall.SIGTERM, syscall.SIGKILL,
+ }
+)
+
+// TerminalWidth returns width of the terminal.
+func TerminalWidth() (int, error) {
+ return 0, errors.New("Not supported")
+}
+
+func lockEcho() error {
+ if consctl != nil {
+ return errors.New("consctl already open")
+ }
+ var err error
+ consctl, err = os.OpenFile("/dev/consctl", os.O_WRONLY, 0)
+ if err != nil {
+ return err
+ }
+ _, err = consctl.WriteString("rawon")
+ if err != nil {
+ consctl.Close()
+ consctl = nil
+ return err
+ }
+ return nil
+}
+
+func unlockEcho() error {
+ if consctl == nil {
+ return nil
+ }
+ if err := consctl.Close(); err != nil {
+ return err
+ }
+ consctl = nil
+ return nil
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/termutil/term_solaris.go b/vendor/github.com/cheggaaa/pb/v3/termutil/term_solaris.go
new file mode 100644
index 0000000..45f3055
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/termutil/term_solaris.go
@@ -0,0 +1,8 @@
+//go:build solaris && !appengine
+// +build solaris,!appengine
+
+package termutil
+
+const ioctlReadTermios = 0x5401 // syscall.TCGETS
+const ioctlWriteTermios = 0x5402 // syscall.TCSETS
+const sysIoctl = 54
diff --git a/vendor/github.com/cheggaaa/pb/v3/termutil/term_win.go b/vendor/github.com/cheggaaa/pb/v3/termutil/term_win.go
new file mode 100644
index 0000000..99397a0
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/termutil/term_win.go
@@ -0,0 +1,155 @@
+//go:build windows
+// +build windows
+
+package termutil
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "strconv"
+ "syscall"
+ "unsafe"
+)
+
+var (
+ tty = os.Stdin
+
+ unlockSignals = []os.Signal{
+ os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL,
+ }
+)
+
+var (
+ kernel32 = syscall.NewLazyDLL("kernel32.dll")
+
+ // GetConsoleScreenBufferInfo retrieves information about the
+ // specified console screen buffer.
+ // http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx
+ procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo")
+
+ // GetConsoleMode retrieves the current input mode of a console's
+ // input buffer or the current output mode of a console screen buffer.
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/ms683167(v=vs.85).aspx
+ getConsoleMode = kernel32.NewProc("GetConsoleMode")
+
+ // SetConsoleMode sets the input mode of a console's input buffer
+ // or the output mode of a console screen buffer.
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/ms686033(v=vs.85).aspx
+ setConsoleMode = kernel32.NewProc("SetConsoleMode")
+
+ // SetConsoleCursorPosition sets the cursor position in the
+ // specified console screen buffer.
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/ms686025(v=vs.85).aspx
+ setConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition")
+
+ mingw = isMingw()
+)
+
+type (
+ // Defines the coordinates of the upper left and lower right corners
+ // of a rectangle.
+ // See
+ // http://msdn.microsoft.com/en-us/library/windows/desktop/ms686311(v=vs.85).aspx
+ smallRect struct {
+ Left, Top, Right, Bottom int16
+ }
+
+ // Defines the coordinates of a character cell in a console screen
+ // buffer. The origin of the coordinate system (0,0) is at the top, left cell
+ // of the buffer.
+ // See
+ // http://msdn.microsoft.com/en-us/library/windows/desktop/ms682119(v=vs.85).aspx
+ coordinates struct {
+ X, Y int16
+ }
+
+ word int16
+
+ // Contains information about a console screen buffer.
+ // http://msdn.microsoft.com/en-us/library/windows/desktop/ms682093(v=vs.85).aspx
+ consoleScreenBufferInfo struct {
+ dwSize coordinates
+ dwCursorPosition coordinates
+ wAttributes word
+ srWindow smallRect
+ dwMaximumWindowSize coordinates
+ }
+)
+
+// TerminalWidth returns width of the terminal.
+func TerminalWidth() (width int, err error) {
+ if mingw {
+ return termWidthTPut()
+ }
+ return termWidthCmd()
+}
+
+func termWidthCmd() (width int, err error) {
+ var info consoleScreenBufferInfo
+ _, _, e := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(syscall.Stdout), uintptr(unsafe.Pointer(&info)), 0)
+ if e != 0 {
+ return 0, error(e)
+ }
+ return int(info.dwSize.X) - 1, nil
+}
+
+func isMingw() bool {
+ return os.Getenv("MINGW_PREFIX") != "" || os.Getenv("MSYSTEM") == "MINGW64"
+}
+
+func termWidthTPut() (width int, err error) {
+ // TODO: maybe anybody knows a better way to get it on mintty...
+ var res []byte
+ cmd := exec.Command("tput", "cols")
+ cmd.Stdin = os.Stdin
+ if res, err = cmd.CombinedOutput(); err != nil {
+ return 0, fmt.Errorf("%s: %v", string(res), err)
+ }
+ if len(res) > 1 {
+ res = res[:len(res)-1]
+ }
+ return strconv.Atoi(string(res))
+}
+
+func GetCursorPos() (pos coordinates, err error) {
+ var info consoleScreenBufferInfo
+ _, _, e := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(syscall.Stdout), uintptr(unsafe.Pointer(&info)), 0)
+ if e != 0 {
+ return info.dwCursorPosition, error(e)
+ }
+ return info.dwCursorPosition, nil
+}
+
+func SetCursorPos(pos coordinates) error {
+ _, _, e := syscall.Syscall(setConsoleCursorPosition.Addr(), 2, uintptr(syscall.Stdout), uintptr(uint32(uint16(pos.Y))<<16|uint32(uint16(pos.X))), 0)
+ if e != 0 {
+ return error(e)
+ }
+ return nil
+}
+
+var oldState word
+
+func lockEcho() (err error) {
+ if _, _, e := syscall.Syscall(getConsoleMode.Addr(), 2, uintptr(syscall.Stdout), uintptr(unsafe.Pointer(&oldState)), 0); e != 0 {
+ err = fmt.Errorf("Can't get terminal settings: %v", e)
+ return
+ }
+
+ newState := oldState
+ const ENABLE_LINE_INPUT = 0x0002
+ newState = newState & (^ENABLE_LINE_INPUT)
+ if _, _, e := syscall.Syscall(setConsoleMode.Addr(), 2, uintptr(syscall.Stdout), uintptr(newState), 0); e != 0 {
+ err = fmt.Errorf("Can't set terminal settings: %v", e)
+ return
+ }
+ return
+}
+
+func unlockEcho() (err error) {
+ if _, _, e := syscall.Syscall(setConsoleMode.Addr(), 2, uintptr(syscall.Stdout), uintptr(oldState), 0); e != 0 {
+ err = fmt.Errorf("Can't set terminal settings")
+ }
+ return
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/termutil/term_x.go b/vendor/github.com/cheggaaa/pb/v3/termutil/term_x.go
new file mode 100644
index 0000000..4746e9b
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/termutil/term_x.go
@@ -0,0 +1,81 @@
+//go:build (linux || darwin || freebsd || netbsd || openbsd || solaris || dragonfly) && !appengine
+// +build linux darwin freebsd netbsd openbsd solaris dragonfly
+// +build !appengine
+
+package termutil
+
+import (
+ "fmt"
+ "os"
+ "syscall"
+ "unsafe"
+)
+
+var (
+ tty *os.File
+
+ unlockSignals = []os.Signal{
+ os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGKILL,
+ }
+ oldState syscall.Termios
+)
+
+type window struct {
+ Row uint16
+ Col uint16
+ Xpixel uint16
+ Ypixel uint16
+}
+
+func init() {
+ var err error
+ tty, err = os.Open("/dev/tty")
+ if err != nil {
+ tty = os.Stdin
+ }
+}
+
+// TerminalWidth returns width of the terminal.
+func TerminalWidth() (int, error) {
+ _, c, err := TerminalSize()
+ return c, err
+}
+
+// TerminalSize returns size of the terminal.
+func TerminalSize() (rows, cols int, err error) {
+ w := new(window)
+ res, _, err := syscall.Syscall(sysIoctl,
+ tty.Fd(),
+ uintptr(syscall.TIOCGWINSZ),
+ uintptr(unsafe.Pointer(w)),
+ )
+ if int(res) == -1 {
+ return 0, 0, err
+ }
+ return int(w.Row), int(w.Col), nil
+}
+
+func lockEcho() error {
+ fd := tty.Fd()
+
+ if _, _, err := syscall.Syscall(sysIoctl, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&oldState))); err != 0 {
+ return fmt.Errorf("error when puts the terminal connected to the given file descriptor: %w", err)
+ }
+
+ newState := oldState
+ newState.Lflag &^= syscall.ECHO
+ newState.Lflag |= syscall.ICANON | syscall.ISIG
+ newState.Iflag |= syscall.ICRNL
+ if _, _, e := syscall.Syscall(sysIoctl, fd, ioctlWriteTermios, uintptr(unsafe.Pointer(&newState))); e != 0 {
+ return fmt.Errorf("error update terminal settings: %w", e)
+ }
+ return nil
+}
+
+func unlockEcho() error {
+ fd := tty.Fd()
+ if _, _, err := syscall.Syscall(sysIoctl, fd, ioctlWriteTermios, uintptr(unsafe.Pointer(&oldState))); err != 0 {
+ return fmt.Errorf("error restores the terminal connected to the given file descriptor: %w", err)
+ }
+ return nil
+}
diff --git a/vendor/github.com/cheggaaa/pb/v3/util.go b/vendor/github.com/cheggaaa/pb/v3/util.go
new file mode 100644
index 0000000..a392605
--- /dev/null
+++ b/vendor/github.com/cheggaaa/pb/v3/util.go
@@ -0,0 +1,116 @@
+package pb
+
+import (
+ "bytes"
+ "fmt"
+ "github.com/mattn/go-runewidth"
+ "math"
+ "regexp"
+ //"unicode/utf8"
+)
+
+const (
+ _KiB = 1024
+ _MiB = 1048576
+ _GiB = 1073741824
+ _TiB = 1099511627776
+
+ _kB = 1e3
+ _MB = 1e6
+ _GB = 1e9
+ _TB = 1e12
+)
+
+var ctrlFinder = regexp.MustCompile("\x1b\x5b[0-9;]+\x6d")
+
+func CellCount(s string) int {
+ n := runewidth.StringWidth(s)
+ for _, sm := range ctrlFinder.FindAllString(s, -1) {
+ n -= runewidth.StringWidth(sm)
+ }
+ return n
+}
+
+func StripString(s string, w int) string {
+ l := CellCount(s)
+ if l <= w {
+ return s
+ }
+ var buf = bytes.NewBuffer(make([]byte, 0, len(s)))
+ StripStringToBuffer(s, w, buf)
+ return buf.String()
+}
+
+func StripStringToBuffer(s string, w int, buf *bytes.Buffer) {
+ var seqs = ctrlFinder.FindAllStringIndex(s, -1)
+ var maxWidthReached bool
+mainloop:
+ for i, r := range s {
+ for _, seq := range seqs {
+ if i >= seq[0] && i < seq[1] {
+ buf.WriteRune(r)
+ continue mainloop
+ }
+ }
+ if rw := CellCount(string(r)); rw <= w && !maxWidthReached {
+ w -= rw
+ buf.WriteRune(r)
+ } else {
+ maxWidthReached = true
+ }
+ }
+ for w > 0 {
+ buf.WriteByte(' ')
+ w--
+ }
+ return
+}
+
+func round(val float64) (newVal float64) {
+ roundOn := 0.5
+ places := 0
+ var round float64
+ pow := math.Pow(10, float64(places))
+ digit := pow * val
+ _, div := math.Modf(digit)
+ if div >= roundOn {
+ round = math.Ceil(digit)
+ } else {
+ round = math.Floor(digit)
+ }
+ newVal = round / pow
+ return
+}
+
+// Convert bytes to human readable string. Like a 2 MiB, 64.2 KiB, or 2 MB, 64.2 kB
+// if useSIPrefix is set to true
+func formatBytes(i int64, useSIPrefix bool) (result string) {
+ if !useSIPrefix {
+ switch {
+ case i >= _TiB:
+ result = fmt.Sprintf("%.02f TiB", float64(i)/_TiB)
+ case i >= _GiB:
+ result = fmt.Sprintf("%.02f GiB", float64(i)/_GiB)
+ case i >= _MiB:
+ result = fmt.Sprintf("%.02f MiB", float64(i)/_MiB)
+ case i >= _KiB:
+ result = fmt.Sprintf("%.02f KiB", float64(i)/_KiB)
+ default:
+ result = fmt.Sprintf("%d B", i)
+ }
+ } else {
+ switch {
+ case i >= _TB:
+ result = fmt.Sprintf("%.02f TB", float64(i)/_TB)
+ case i >= _GB:
+ result = fmt.Sprintf("%.02f GB", float64(i)/_GB)
+ case i >= _MB:
+ result = fmt.Sprintf("%.02f MB", float64(i)/_MB)
+ case i >= _kB:
+ result = fmt.Sprintf("%.02f kB", float64(i)/_kB)
+ default:
+ result = fmt.Sprintf("%d B", i)
+ }
+ }
+ return
+}