1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/gui/presentation/worktrees.go

52 lines
1.3 KiB
Go
Raw Normal View History

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"
2023-07-17 14:03:51 +02:00
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/jesseduffield/lazygit/pkg/theme"
2023-07-16 03:45:08 +02:00
"github.com/samber/lo"
)
func GetWorktreeDisplayStrings(tr *i18n.TranslationSet, worktrees []*models.Worktree) [][]string {
2023-07-16 03:45:08 +02:00
return lo.Map(worktrees, func(worktree *models.Worktree, _ int) []string {
return GetWorktreeDisplayString(
2023-07-17 14:03:51 +02:00
tr,
2023-07-16 03:45:08 +02:00
worktree)
})
}
func GetWorktreeDisplayString(tr *i18n.TranslationSet, worktree *models.Worktree) []string {
textStyle := theme.DefaultTextColor
current := ""
currentColor := style.FgCyan
if worktree.IsCurrent {
current = " *"
currentColor = style.FgGreen
}
2023-07-16 03:45:08 +02:00
icon := icons.IconForWorktree(false)
if worktree.IsPathMissing {
textStyle = style.FgRed
2023-07-16 03:45:08 +02:00
icon = icons.IconForWorktree(true)
}
2023-07-16 03:45:08 +02:00
res := []string{}
res = append(res, currentColor.Sprint(current))
if icons.IsIconEnabled() {
res = append(res, textStyle.Sprint(icon))
}
2023-07-16 05:43:20 +02:00
name := worktree.Name
if worktree.IsMain {
2023-07-17 14:03:51 +02:00
name += " " + tr.MainWorktree
}
if worktree.IsPathMissing && !icons.IsIconEnabled() {
2023-07-17 14:03:51 +02:00
name += " " + tr.MissingWorktree
2023-07-16 05:43:20 +02:00
}
res = append(res, textStyle.Sprint(name))
return res
}