mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-03 00:57:52 +02:00
We're doing all the IO in our workers loader method so that we don't need to do any in our presentation code
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package presentation
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
|
"github.com/jesseduffield/lazygit/pkg/i18n"
|
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
|
"github.com/samber/lo"
|
|
)
|
|
|
|
func GetWorktreeDisplayStrings(tr *i18n.TranslationSet, worktrees []*models.Worktree) [][]string {
|
|
return lo.Map(worktrees, func(worktree *models.Worktree, _ int) []string {
|
|
return GetWorktreeDisplayString(
|
|
tr,
|
|
worktree)
|
|
})
|
|
}
|
|
|
|
func GetWorktreeDisplayString(tr *i18n.TranslationSet, worktree *models.Worktree) []string {
|
|
textStyle := theme.DefaultTextColor
|
|
|
|
current := ""
|
|
currentColor := style.FgCyan
|
|
if worktree.Current() {
|
|
current = " *"
|
|
currentColor = style.FgGreen
|
|
}
|
|
|
|
icon := icons.IconForWorktree(false)
|
|
if worktree.PathMissing() {
|
|
textStyle = style.FgRed
|
|
icon = icons.IconForWorktree(true)
|
|
}
|
|
|
|
res := []string{}
|
|
res = append(res, currentColor.Sprint(current))
|
|
if icons.IsIconEnabled() {
|
|
res = append(res, textStyle.Sprint(icon))
|
|
}
|
|
|
|
name := worktree.Name()
|
|
if worktree.Main() {
|
|
name += " " + tr.MainWorktree
|
|
}
|
|
if worktree.PathMissing() && !icons.IsIconEnabled() {
|
|
name += " " + tr.MissingWorktree
|
|
}
|
|
res = append(res, textStyle.Sprint(name))
|
|
return res
|
|
}
|