Skip to content

Commit 252dda5

Browse files
committed
Move Loader to presentation package
It is very gui specific and shouldn't be in a low-level utils package.
1 parent a6a6877 commit 252dda5

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

pkg/gui/presentation/branches.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func BranchStatus(
165165
) string {
166166
itemOperationStr := ItemOperationToString(itemOperation, tr)
167167
if itemOperationStr != "" {
168-
return style.FgCyan.Sprintf("%s %s", itemOperationStr, utils.Loader(now, userConfig.Gui.Spinner))
168+
return style.FgCyan.Sprintf("%s %s", itemOperationStr, Loader(now, userConfig.Gui.Spinner))
169169
}
170170

171171
result := ""

pkg/gui/presentation/loader.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package presentation
2+
3+
import (
4+
"time"
5+
6+
"github.com/jesseduffield/lazygit/pkg/config"
7+
)
8+
9+
// Loader dumps a string to be displayed as a loader
10+
func Loader(now time.Time, config config.SpinnerConfig) string {
11+
milliseconds := now.UnixMilli()
12+
index := milliseconds / int64(config.Rate) % int64(len(config.Frames))
13+
return config.Frames[index]
14+
}

pkg/gui/presentation/remotes.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/jesseduffield/lazygit/pkg/gui/types"
1111
"github.com/jesseduffield/lazygit/pkg/i18n"
1212
"github.com/jesseduffield/lazygit/pkg/theme"
13-
"github.com/jesseduffield/lazygit/pkg/utils"
1413
"github.com/samber/lo"
1514
)
1615

@@ -49,7 +48,7 @@ func getRemoteDisplayStrings(
4948
descriptionStr := style.FgBlue.Sprintf("%d branches", branchCount)
5049
itemOperationStr := ItemOperationToString(itemOperation, tr)
5150
if itemOperationStr != "" {
52-
descriptionStr += " " + style.FgCyan.Sprint(itemOperationStr+" "+utils.Loader(time.Now(), userConfig.Gui.Spinner))
51+
descriptionStr += " " + style.FgCyan.Sprint(itemOperationStr+" "+Loader(time.Now(), userConfig.Gui.Spinner))
5352
}
5453
res = append(res, textStyle.Sprint(r.Name), descriptionStr)
5554
return res

pkg/gui/presentation/tags.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/jesseduffield/lazygit/pkg/gui/types"
1111
"github.com/jesseduffield/lazygit/pkg/i18n"
1212
"github.com/jesseduffield/lazygit/pkg/theme"
13-
"github.com/jesseduffield/lazygit/pkg/utils"
1413
"github.com/samber/lo"
1514
)
1615

@@ -47,7 +46,7 @@ func getTagDisplayStrings(
4746
descriptionStr := descriptionColor.Sprint(t.Description())
4847
itemOperationStr := ItemOperationToString(itemOperation, tr)
4948
if itemOperationStr != "" {
50-
descriptionStr = style.FgCyan.Sprint(itemOperationStr+" "+utils.Loader(time.Now(), userConfig.Gui.Spinner)) + " " + descriptionStr
49+
descriptionStr = style.FgCyan.Sprint(itemOperationStr+" "+Loader(time.Now(), userConfig.Gui.Spinner)) + " " + descriptionStr
5150
}
5251
res = append(res, textStyle.Sprint(t.Name), descriptionStr)
5352
return res

pkg/gui/status/status_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55

66
"github.com/jesseduffield/gocui"
77
"github.com/jesseduffield/lazygit/pkg/config"
8+
"github.com/jesseduffield/lazygit/pkg/gui/presentation"
89
"github.com/jesseduffield/lazygit/pkg/gui/types"
9-
"github.com/jesseduffield/lazygit/pkg/utils"
1010
"github.com/samber/lo"
1111
"github.com/sasha-s/go-deadlock"
1212
)
@@ -75,7 +75,7 @@ func (self *StatusManager) GetStatusString(userConfig *config.UserConfig) (strin
7575
}
7676
topStatus := self.statuses[0]
7777
if topStatus.statusType == "waiting" {
78-
return topStatus.message + " " + utils.Loader(time.Now(), userConfig.Gui.Spinner), topStatus.color
78+
return topStatus.message + " " + presentation.Loader(time.Now(), userConfig.Gui.Spinner), topStatus.color
7979
}
8080
return topStatus.message, topStatus.color
8181
}

pkg/utils/utils.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import (
88
"runtime"
99
"strconv"
1010
"strings"
11-
"time"
1211

1312
"github.com/jesseduffield/gocui"
14-
"github.com/jesseduffield/lazygit/pkg/config"
1513
)
1614

1715
// GetProjectRoot returns the path to the root of the project. Only to be used
@@ -25,13 +23,6 @@ func GetProjectRoot() string {
2523
return strings.Split(dir, "lazygit")[0] + "lazygit"
2624
}
2725

28-
// Loader dumps a string to be displayed as a loader
29-
func Loader(now time.Time, config config.SpinnerConfig) string {
30-
milliseconds := now.UnixMilli()
31-
index := milliseconds / int64(config.Rate) % int64(len(config.Frames))
32-
return config.Frames[index]
33-
}
34-
3526
func SortRange(x int, y int) (int, int) {
3627
if x < y {
3728
return x, y

0 commit comments

Comments
 (0)