Fix Throbber Linebreak
This commit is contained in:
+21
-4
@@ -31,10 +31,11 @@ type context struct {
|
||||
}
|
||||
|
||||
type spinner struct {
|
||||
mu sync.Mutex
|
||||
on bool
|
||||
text string
|
||||
msg []string
|
||||
mu sync.Mutex
|
||||
on bool
|
||||
text string
|
||||
msg []string
|
||||
painted bool
|
||||
}
|
||||
|
||||
var spin = &spinner{
|
||||
@@ -53,6 +54,19 @@ func (s *spinner) stop() {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.on = false
|
||||
if s.painted {
|
||||
fmt.Fprint(os.Stderr, "\r\033[K\n")
|
||||
s.painted = false
|
||||
}
|
||||
}
|
||||
|
||||
func (s *spinner) linebreak() {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.on && s.painted {
|
||||
fmt.Fprint(os.Stderr, "\r\033[K\n")
|
||||
s.painted = false
|
||||
}
|
||||
}
|
||||
|
||||
func (s *spinner) run(text string) {
|
||||
@@ -66,6 +80,7 @@ func (s *spinner) run(text string) {
|
||||
}
|
||||
msg := s.msg[i%len(s.msg)]
|
||||
fmt.Fprintf(os.Stderr, "\r[%s] %s", msg, text)
|
||||
s.painted = true
|
||||
s.mu.Unlock()
|
||||
i++
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
@@ -224,6 +239,7 @@ func runBuildModule(ctx context) error {
|
||||
}
|
||||
|
||||
result, err := pipeline.BuildModuleWithProgress(p, func(message string) {
|
||||
spin.linebreak()
|
||||
fmt.Fprintf(ctx.stdout, "[build-module] %s\n", message)
|
||||
})
|
||||
if err != nil {
|
||||
@@ -259,6 +275,7 @@ func runBuildHAKs(ctx context) error {
|
||||
}
|
||||
|
||||
progress := func(message string) {
|
||||
spin.linebreak()
|
||||
fmt.Fprintf(ctx.stdout, "[build-haks] %s\n", message)
|
||||
}
|
||||
var result pipeline.BuildResult
|
||||
|
||||
Reference in New Issue
Block a user