mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-17 00:18:05 +02:00
Add constant for LoaderAnimationInterval
Since Loader and renderAppStatus need to agree on it, it helps for it to be a constant in case we want to change it.
This commit is contained in:
@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/status"
|
"github.com/jesseduffield/lazygit/pkg/gui/status"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AppStatusHelper struct {
|
type AppStatusHelper struct {
|
||||||
@ -77,7 +78,7 @@ func (self *AppStatusHelper) GetStatusString() string {
|
|||||||
|
|
||||||
func (self *AppStatusHelper) renderAppStatus() {
|
func (self *AppStatusHelper) renderAppStatus() {
|
||||||
self.c.OnWorker(func(_ gocui.Task) {
|
self.c.OnWorker(func(_ gocui.Task) {
|
||||||
ticker := time.NewTicker(time.Millisecond * 50)
|
ticker := time.NewTicker(time.Millisecond * utils.LoaderAnimationInterval)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
for range ticker.C {
|
for range ticker.C {
|
||||||
appStatus := self.statusMgr().GetStatusString()
|
appStatus := self.statusMgr().GetStatusString()
|
||||||
|
@ -24,12 +24,15 @@ func GetProjectRoot() string {
|
|||||||
return strings.Split(dir, "lazygit")[0] + "lazygit"
|
return strings.Split(dir, "lazygit")[0] + "lazygit"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The duration between two frames of the loader animation in milliseconds
|
||||||
|
const LoaderAnimationInterval = 50
|
||||||
|
|
||||||
// Loader dumps a string to be displayed as a loader
|
// Loader dumps a string to be displayed as a loader
|
||||||
func Loader() string {
|
func Loader() string {
|
||||||
characters := "|/-\\"
|
characters := "|/-\\"
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
nanos := now.UnixNano()
|
milliseconds := now.UnixMilli()
|
||||||
index := nanos / 50000000 % int64(len(characters))
|
index := milliseconds / LoaderAnimationInterval % int64(len(characters))
|
||||||
return characters[index : index+1]
|
return characters[index : index+1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user