-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Blaize Kaye
committed
Jan 17, 2025
1 parent
fe0a748
commit c03a8c8
Showing
5 changed files
with
73 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package utils | ||
|
||
import ( | ||
spinner2 "github.com/briandowns/spinner" | ||
"sync" | ||
"time" | ||
) | ||
|
||
// This package controls whether there's a spinner displayed or not. To be used in longer running processes. | ||
// Mainly, it's a wrapper around briandowns/spinner. | ||
|
||
var showSpinner bool | ||
var spinnerMx sync.Mutex | ||
|
||
var spinner *spinner2.Spinner | ||
|
||
func SetShowSpinner(spin bool) { | ||
spinnerMx.Lock() | ||
defer spinnerMx.Unlock() | ||
showSpinner = spin | ||
} | ||
|
||
func ShowSpinner() { | ||
spinnerMx.Lock() | ||
defer spinnerMx.Unlock() | ||
if showSpinner { | ||
if spinner != nil { | ||
if spinner.Active() { | ||
return | ||
} | ||
} else { | ||
spinner = spinner2.New(spinner2.CharSets[9], 100*time.Millisecond) | ||
} | ||
spinner.Start() | ||
} | ||
} | ||
|
||
func HideSpinner() { | ||
spinnerMx.Lock() | ||
defer spinnerMx.Unlock() | ||
if showSpinner && spinner != nil { | ||
if spinner.Active() { | ||
spinner.Stop() | ||
} | ||
spinner = nil | ||
} | ||
} | ||
|
||
func init() { | ||
spinnerMx = sync.Mutex{} | ||
} |