From 64c0d40eca57e9558765b0035f268c896af46bb9 Mon Sep 17 00:00:00 2001 From: Rene Cunningham Date: Wed, 27 Jan 2021 16:29:15 +1100 Subject: [PATCH] Bump briandowns/spinner to resolve race condition issue. See https://github.com/briandowns/spinner/issues/99. --- go.mod | 2 +- go.sum | 2 + .../github.com/briandowns/spinner/README.md | 94 +++++++++---------- .../github.com/briandowns/spinner/spinner.go | 30 +++--- vendor/modules.txt | 2 +- 5 files changed, 63 insertions(+), 67 deletions(-) diff --git a/go.mod b/go.mod index 44c92913e..314169750 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.14 require ( github.com/AlecAivazis/survey/v2 v2.2.7 github.com/benbjohnson/clock v1.1.0 // indirect - github.com/briandowns/spinner v1.11.1 + github.com/briandowns/spinner v1.12.0 github.com/fatih/color v1.9.0 // indirect github.com/golang/mock v1.4.4 github.com/google/go-cmp v0.5.4 diff --git a/go.sum b/go.sum index 4c9f4bf0a..c452a9d96 100644 --- a/go.sum +++ b/go.sum @@ -52,6 +52,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/briandowns/spinner v1.11.1 h1:OixPqDEcX3juo5AjQZAnFPbeUA0jvkp2qzB5gOZJ/L0= github.com/briandowns/spinner v1.11.1/go.mod h1:QOuQk7x+EaDASo80FEXwlwiA+j/PPIcX3FScO+3/ZPQ= +github.com/briandowns/spinner v1.12.0 h1:72O0PzqGJb6G3KgrcIOtL/JAGGZ5ptOMCn9cUHmqsmw= +github.com/briandowns/spinner v1.12.0/go.mod h1:QOuQk7x+EaDASo80FEXwlwiA+j/PPIcX3FScO+3/ZPQ= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= diff --git a/vendor/github.com/briandowns/spinner/README.md b/vendor/github.com/briandowns/spinner/README.md index 516b0f37d..ddae178b6 100644 --- a/vendor/github.com/briandowns/spinner/README.md +++ b/vendor/github.com/briandowns/spinner/README.md @@ -17,52 +17,52 @@ go get github.com/briandowns/spinner ## Available Character Sets (Numbered by their slice index) -index | character set | sample gif -------|---------------|--------------- -0 | ```←↖↑↗→↘↓↙``` | ![Sample Gif](gifs/0.gif) -1 | ```▁▃▄▅▆▇█▇▆▅▄▃▁``` | ![Sample Gif](gifs/1.gif) -2 | ```▖▘▝▗``` | ![Sample Gif](gifs/2.gif) -3 | ```┤┘┴└├┌┬┐``` | ![Sample Gif](gifs/3.gif) -4 | ```◢◣◤◥``` | ![Sample Gif](gifs/4.gif) -5 | ```◰◳◲◱``` | ![Sample Gif](gifs/5.gif) -6 | ```◴◷◶◵``` | ![Sample Gif](gifs/6.gif) -7 | ```◐◓◑◒``` | ![Sample Gif](gifs/7.gif) -8 | ```.oO@*``` | ![Sample Gif](gifs/8.gif) -9 | ```\|/-\``` | ![Sample Gif](gifs/9.gif) -10 | ```◡◡⊙⊙◠◠``` | ![Sample Gif](gifs/10.gif) -11 | ```⣾⣽⣻⢿⡿⣟⣯⣷``` | ![Sample Gif](gifs/11.gif) -12 | ```>))'> >))'> >))'> >))'> >))'> <'((< <'((< <'((<``` | ![Sample Gif](gifs/12.gif) -13 | ```⠁⠂⠄⡀⢀⠠⠐⠈``` | ![Sample Gif](gifs/13.gif) -14 | ```⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏``` | ![Sample Gif](gifs/14.gif) -15 | ```abcdefghijklmnopqrstuvwxyz``` | ![Sample Gif](gifs/15.gif) -16 | ```▉▊▋▌▍▎▏▎▍▌▋▊▉``` | ![Sample Gif](gifs/16.gif) -17 | ```■□▪▫``` | ![Sample Gif](gifs/17.gif) -18 | ```←↑→↓``` | ![Sample Gif](gifs/18.gif) -19 | ```╫╪``` | ![Sample Gif](gifs/19.gif) -20 | ```⇐⇖⇑⇗⇒⇘⇓⇙``` | ![Sample Gif](gifs/20.gif) -21 | ```⠁⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈⠈``` | ![Sample Gif](gifs/21.gif) -22 | ```⠈⠉⠋⠓⠒⠐⠐⠒⠖⠦⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈``` | ![Sample Gif](gifs/22.gif) -23 | ```⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠴⠲⠒⠂⠂⠒⠚⠙⠉⠁``` | ![Sample Gif](gifs/23.gif) -24 | ```⠋⠙⠚⠒⠂⠂⠒⠲⠴⠦⠖⠒⠐⠐⠒⠓⠋``` | ![Sample Gif](gifs/24.gif) -25 | ```ヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン``` | ![Sample Gif](gifs/25.gif) -26 | ```. .. ...``` | ![Sample Gif](gifs/26.gif) -27 | ```▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▏▎▍▌▋▊▉█▇▆▅▄▃▂▁``` | ![Sample Gif](gifs/27.gif) -28 | ```.oO°Oo.``` | ![Sample Gif](gifs/28.gif) -29 | ```+x``` | ![Sample Gif](gifs/29.gif) -30 | ```v<^>``` | ![Sample Gif](gifs/30.gif) -31 | ```>>---> >>---> >>---> >>---> >>---> <---<< <---<< <---<< <---<< <---<<``` | ![Sample Gif](gifs/31.gif) -32 | ```\| \|\| \|\|\| \|\|\|\| \|\|\|\|\| \|\|\|\|\|\| \|\|\|\|\| \|\|\|\| \|\|\| \|\| \|``` | ![Sample Gif](gifs/32.gif) -33 | ```[] [=] [==] [===] [====] [=====] [======] [=======] [========] [=========] [==========]``` | ![Sample Gif](gifs/33.gif) -34 | ```(*---------) (-*--------) (--*-------) (---*------) (----*-----) (-----*----) (------*---) (-------*--) (--------*-) (---------*)``` | ![Sample Gif](gifs/34.gif) -35 | ```█▒▒▒▒▒▒▒▒▒ ███▒▒▒▒▒▒▒ █████▒▒▒▒▒ ███████▒▒▒ ██████████``` | ![Sample Gif](gifs/35.gif) -36 | ```[ ] [=> ] [===> ] [=====> ] [======> ] [========> ] [==========> ] [============> ] [==============> ] [================> ] [==================> ] [===================>]``` | ![Sample Gif](gifs/36.gif) -37 | ```🕐 🕑 🕒 🕓 🕔 🕕 🕖 🕗 🕘 🕙 🕚 🕛``` | ![Sample Gif](gifs/37.gif) -38 | ```🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🕛 🕧``` | ![Sample Gif](gifs/38.gif) -39 | ```🌍 🌎 🌏``` | ![Sample Gif](gifs/39.gif) -40 | ```◜ ◝ ◞ ◟``` | ![Sample Gif](gifs/40.gif) -41 | ```⬒ ⬔ ⬓ ⬕``` | ![Sample Gif](gifs/41.gif) -42 | ```⬖ ⬘ ⬗ ⬙``` | ![Sample Gif](gifs/42.gif) -43 | ```[>>> >] []>>>> [] [] >>>> [] [] >>>> [] [] >>>> [] [] >>>>[] [>> >>]``` | ![Sample Gif](gifs/43.gif) +| index | character set | sample gif | +| ----- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | +| 0 | ```←↖↑↗→↘↓↙``` | ![Sample Gif](gifs/0.gif) | +| 1 | ```▁▃▄▅▆▇█▇▆▅▄▃▁``` | ![Sample Gif](gifs/1.gif) | +| 2 | ```▖▘▝▗``` | ![Sample Gif](gifs/2.gif) | +| 3 | ```┤┘┴└├┌┬┐``` | ![Sample Gif](gifs/3.gif) | +| 4 | ```◢◣◤◥``` | ![Sample Gif](gifs/4.gif) | +| 5 | ```◰◳◲◱``` | ![Sample Gif](gifs/5.gif) | +| 6 | ```◴◷◶◵``` | ![Sample Gif](gifs/6.gif) | +| 7 | ```◐◓◑◒``` | ![Sample Gif](gifs/7.gif) | +| 8 | ```.oO@*``` | ![Sample Gif](gifs/8.gif) | +| 9 | ```\|/-\``` | ![Sample Gif](gifs/9.gif) | +| 10 | ```◡◡⊙⊙◠◠``` | ![Sample Gif](gifs/10.gif) | +| 11 | ```⣾⣽⣻⢿⡿⣟⣯⣷``` | ![Sample Gif](gifs/11.gif) | +| 12 | ```>))'> >))'> >))'> >))'> >))'> <'((< <'((< <'((<``` | ![Sample Gif](gifs/12.gif) | +| 13 | ```⠁⠂⠄⡀⢀⠠⠐⠈``` | ![Sample Gif](gifs/13.gif) | +| 14 | ```⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏``` | ![Sample Gif](gifs/14.gif) | +| 15 | ```abcdefghijklmnopqrstuvwxyz``` | ![Sample Gif](gifs/15.gif) | +| 16 | ```▉▊▋▌▍▎▏▎▍▌▋▊▉``` | ![Sample Gif](gifs/16.gif) | +| 17 | ```■□▪▫``` | ![Sample Gif](gifs/17.gif) | +| 18 | ```←↑→↓``` | ![Sample Gif](gifs/18.gif) | +| 19 | ```╫╪``` | ![Sample Gif](gifs/19.gif) | +| 20 | ```⇐⇖⇑⇗⇒⇘⇓⇙``` | ![Sample Gif](gifs/20.gif) | +| 21 | ```⠁⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈⠈``` | ![Sample Gif](gifs/21.gif) | +| 22 | ```⠈⠉⠋⠓⠒⠐⠐⠒⠖⠦⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈``` | ![Sample Gif](gifs/22.gif) | +| 23 | ```⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠴⠲⠒⠂⠂⠒⠚⠙⠉⠁``` | ![Sample Gif](gifs/23.gif) | +| 24 | ```⠋⠙⠚⠒⠂⠂⠒⠲⠴⠦⠖⠒⠐⠐⠒⠓⠋``` | ![Sample Gif](gifs/24.gif) | +| 25 | ```ヲァィゥェォャュョッアイウエオカキクケコサシスセソタチツテトナニヌネノハヒフヘホマミムメモヤユヨラリルレロワン``` | ![Sample Gif](gifs/25.gif) | +| 26 | ```. .. ...``` | ![Sample Gif](gifs/26.gif) | +| 27 | ```▁▂▃▄▅▆▇█▉▊▋▌▍▎▏▏▎▍▌▋▊▉█▇▆▅▄▃▂▁``` | ![Sample Gif](gifs/27.gif) | +| 28 | ```.oO°Oo.``` | ![Sample Gif](gifs/28.gif) | +| 29 | ```+x``` | ![Sample Gif](gifs/29.gif) | +| 30 | ```v<^>``` | ![Sample Gif](gifs/30.gif) | +| 31 | ```>>---> >>---> >>---> >>---> >>---> <---<< <---<< <---<< <---<< <---<<``` | ![Sample Gif](gifs/31.gif) | +| 32 | ```\| \|\| \|\|\| \|\|\|\| \|\|\|\|\| \|\|\|\|\|\| \|\|\|\|\| \|\|\|\| \|\|\| \|\| \|``` | ![Sample Gif](gifs/32.gif) | +| 33 | ```[] [=] [==] [===] [====] [=====] [======] [=======] [========] [=========] [==========]``` | ![Sample Gif](gifs/33.gif) | +| 34 | ```(*---------) (-*--------) (--*-------) (---*------) (----*-----) (-----*----) (------*---) (-------*--) (--------*-) (---------*)``` | ![Sample Gif](gifs/34.gif) | +| 35 | ```█▒▒▒▒▒▒▒▒▒ ███▒▒▒▒▒▒▒ █████▒▒▒▒▒ ███████▒▒▒ ██████████``` | ![Sample Gif](gifs/35.gif) | +| 36 | ```[ ] [=> ] [===> ] [=====> ] [======> ] [========> ] [==========> ] [============> ] [==============> ] [================> ] [==================> ] [===================>]``` | ![Sample Gif](gifs/36.gif) | +| 37 | ```🕐 🕑 🕒 🕓 🕔 🕕 🕖 🕗 🕘 🕙 🕚 🕛``` | ![Sample Gif](gifs/37.gif) | +| 38 | ```🕐 🕜 🕑 🕝 🕒 🕞 🕓 🕟 🕔 🕠 🕕 🕡 🕖 🕢 🕗 🕣 🕘 🕤 🕙 🕥 🕚 🕦 🕛 🕧``` | ![Sample Gif](gifs/38.gif) | +| 39 | ```🌍 🌎 🌏``` | ![Sample Gif](gifs/39.gif) | +| 40 | ```◜ ◝ ◞ ◟``` | ![Sample Gif](gifs/40.gif) | +| 41 | ```⬒ ⬔ ⬓ ⬕``` | ![Sample Gif](gifs/41.gif) | +| 42 | ```⬖ ⬘ ⬗ ⬙``` | ![Sample Gif](gifs/42.gif) | +| 43 | ```[>>> >] []>>>> [] [] >>>> [] [] >>>> [] [] >>>> [] [] >>>>[] [>> >>]``` | ![Sample Gif](gifs/43.gif) | ## Features @@ -139,7 +139,7 @@ s.Prefix = "prefixed text: " // Prefix text before the spinner s.Suffix = " :appended text" // Append text after the spinner ``` -## Set or change the color of the spinner. Default color is white. This will restart the spinner with the new color. +## Set or change the color of the spinner. Default color is white. The spinner will need to be restarted to pick up the change. ```Go s.Color("red") // Set the spinner color to red diff --git a/vendor/github.com/briandowns/spinner/spinner.go b/vendor/github.com/briandowns/spinner/spinner.go index 29d98eb09..5ce68703e 100644 --- a/vendor/github.com/briandowns/spinner/spinner.go +++ b/vendor/github.com/briandowns/spinner/spinner.go @@ -14,13 +14,13 @@ package spinner import ( - "encoding/hex" "errors" "fmt" "io" "os" "runtime" "strconv" + "strings" "sync" "time" "unicode/utf8" @@ -285,10 +285,11 @@ func (s *Spinner) Start() { case <-s.stopChan: return default: + s.mu.Lock() if !s.active { + s.mu.Unlock() return } - s.mu.Lock() s.erase() if s.PreUpdate != nil { @@ -303,9 +304,9 @@ func (s *Spinner) Start() { outColor = fmt.Sprintf("\r%s%s%s ", s.Prefix, s.color(s.chars[i]), s.Suffix) } } else { - outColor = fmt.Sprintf("%s%s%s ", s.Prefix, s.color(s.chars[i]), s.Suffix) + outColor = fmt.Sprintf("\r%s%s%s ", s.Prefix, s.color(s.chars[i]), s.Suffix) } - outPlain := fmt.Sprintf("%s%s%s ", s.Prefix, s.chars[i], s.Suffix) + outPlain := fmt.Sprintf("\r%s%s%s ", s.Prefix, s.chars[i], s.Suffix) fmt.Fprint(s.Writer, outColor) s.lastOutput = outPlain delay := s.Delay @@ -334,7 +335,7 @@ func (s *Spinner) Stop() { } s.erase() if s.FinalMSG != "" { - fmt.Fprintf(s.Writer, s.FinalMSG) + fmt.Fprint(s.Writer, s.FinalMSG) } s.stopChan <- struct{}{} } @@ -355,7 +356,8 @@ func (s *Spinner) Reverse() { } } -// Color will set the struct field for the given color to be used. +// Color will set the struct field for the given color to be used. The spinner +// will need to be explicitly restarted. func (s *Spinner) Color(colors ...string) error { colorAttributes := make([]color.Attribute, len(colors)) @@ -370,7 +372,6 @@ func (s *Spinner) Color(colors ...string) error { s.mu.Lock() s.color = color.New(colorAttributes...).SprintFunc() s.mu.Unlock() - s.Restart() return nil } @@ -393,20 +394,13 @@ func (s *Spinner) UpdateCharSet(cs []string) { func (s *Spinner) erase() { n := utf8.RuneCountInString(s.lastOutput) if runtime.GOOS == "windows" { - clearString := "\r" - for i := 0; i < n; i++ { - clearString += " " - } - clearString += "\r" - fmt.Fprintf(s.Writer, clearString) + clearString := "\r" + strings.Repeat(" ", n) + "\r" + fmt.Fprint(s.Writer, clearString) s.lastOutput = "" return } - del, _ := hex.DecodeString("7f") - for _, c := range []string{"\b", string(del)} { - for i := 0; i < n; i++ { - fmt.Fprintf(s.Writer, c) - } + for _, c := range []string{"\b", "\127", "\b", "\033[K"} { // "\033[K" for macOS Terminal + fmt.Fprint(s.Writer, strings.Repeat(c, n)) } fmt.Fprintf(s.Writer, "\r\033[K") // erases to end of line s.lastOutput = "" diff --git a/vendor/modules.txt b/vendor/modules.txt index ce40a8c49..d94973d15 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -7,7 +7,7 @@ github.com/AlecAivazis/survey/v2/terminal github.com/PuerkitoBio/rehttp # github.com/benbjohnson/clock v1.1.0 ## explicit -# github.com/briandowns/spinner v1.11.1 +# github.com/briandowns/spinner v1.12.0 ## explicit github.com/briandowns/spinner # github.com/davecgh/go-spew v1.1.1