diff options
| author | eltrac <hi@eltr.ac> | 2026-05-26 10:00:29 +0800 |
|---|---|---|
| committer | eltrac <hi@eltr.ac> | 2026-05-26 10:00:29 +0800 |
| commit | 36bc242e9db96e14811736379bbcde5ea7b00bd7 (patch) | |
| tree | 718d8d416ef3c1b8ebd193bcbf8074fe68a83212 /animation.go | |
| parent | 4cec245383ab16656e1c5dcbbbe63350b57ab0ea (diff) | |
fix(tui): showing multiple results
Diffstat (limited to 'animation.go')
| -rw-r--r-- | animation.go | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/animation.go b/animation.go index 5d2bc47..8bd94f5 100644 --- a/animation.go +++ b/animation.go @@ -7,22 +7,27 @@ import ( "time" ) -var loadingDone chan bool +var ( + loadingDone chan struct{} + loadingStopped chan struct{} +) func showLoadingPrompt(msg string) { if loadingDone != nil { return } - loadingDone = make(chan bool) + loadingDone = make(chan struct{}) + loadingStopped = make(chan struct{}) go func() { + defer close(loadingStopped) white := color.New(color.FgWhite) for { select { case <-loadingDone: - fmt.Print("\r") // move cursor to line start + fmt.Print("\r") fmt.Print(strings.Repeat(" ", len(msg)+4)) - fmt.Print("\r") // clear line + fmt.Print("\r") return default: white.Printf("\r%s", msg) @@ -39,10 +44,10 @@ func showLoadingPrompt(msg string) { }() } -// hideLoadingPrompt stops the animation cleanly. func hideLoadingPrompt() { if loadingDone != nil { close(loadingDone) + <-loadingStopped loadingDone = nil fmt.Print("\r\033[2K") } |
