Skip to content

Commit

Permalink
Add constant for LoaderAnimationInterval
Browse files Browse the repository at this point in the history
Since Loader and renderAppStatus need to agree on it, it helps for it to be a
constant in case we want to change it.
  • Loading branch information
stefanhaller committed Sep 20, 2023
1 parent 64012d6 commit cdad0b9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion pkg/gui/controllers/helpers/app_status_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/status"
"github.com/jesseduffield/lazygit/pkg/utils"
)

type AppStatusHelper struct {
Expand Down Expand Up @@ -77,7 +78,7 @@ func (self *AppStatusHelper) GetStatusString() string {

func (self *AppStatusHelper) renderAppStatus() {
self.c.OnWorker(func(_ gocui.Task) {
ticker := time.NewTicker(time.Millisecond * 50)
ticker := time.NewTicker(time.Millisecond * utils.LoaderAnimationInterval)
defer ticker.Stop()
for range ticker.C {
appStatus := self.statusMgr().GetStatusString()
Expand Down
7 changes: 5 additions & 2 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ func GetProjectRoot() string {
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
func Loader() string {
characters := "|/-\\"
now := time.Now()
nanos := now.UnixNano()
index := nanos / 50000000 % int64(len(characters))
milliseconds := now.UnixMilli()
index := milliseconds / LoaderAnimationInterval % int64(len(characters))
return characters[index : index+1]
}

Expand Down

0 comments on commit cdad0b9

Please sign in to comment.