Skip to content

Commit

Permalink
Fix the ProgressBar hanging forever at quit
Browse files Browse the repository at this point in the history
  • Loading branch information
cardil committed Mar 21, 2024
1 parent 3b9ddb3 commit 0ff3298
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pkg/output/tui/progress.go
Expand Up @@ -78,7 +78,7 @@ type BubbleProgress struct {
speed int
prevSpeed []int
err error
ended chan struct{}
quitChan chan struct{}
}

func (b *BubbleProgress) With(fn func(ProgressControl) error) error {
Expand Down Expand Up @@ -235,11 +235,11 @@ func (b *BubbleProgress) start() {
tea.WithInput(b.InOrStdin()),
tea.WithOutput(out),
)
b.ended = make(chan struct{})
b.quitChan = make(chan struct{})
go func() {
t := b.tea
_, _ = t.Run()
close(b.ended)
close(b.quitChan)
if term.IsTerminal(out) {
if err := t.ReleaseTerminal(); err != nil {
panic(err)
Expand All @@ -252,11 +252,10 @@ func (b *BubbleProgress) stop() {
if b.tea == nil {
return
}
b.tea.Wait()

<-b.ended
b.tea.Quit()
<-b.quitChan
b.tea = nil
b.ended = nil
b.quitChan = nil
}

func (b *BubbleProgress) onProgress(percent float64) {
Expand Down

0 comments on commit 0ff3298

Please sign in to comment.