mirror of
https://github.com/jesseduffield/lazygit.git
synced 2024-12-12 11:15:00 +02:00
54 lines
1.4 KiB
Go
54 lines
1.4 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, isCurrent func(string) bool, isMissing func(string) bool) [][]string {
|
|
return lo.Map(worktrees, func(worktree *models.Worktree, _ int) []string {
|
|
return GetWorktreeDisplayString(
|
|
tr,
|
|
isCurrent(worktree.Path),
|
|
isMissing(worktree.Path),
|
|
worktree)
|
|
})
|
|
}
|
|
|
|
func GetWorktreeDisplayString(tr *i18n.TranslationSet, isCurrent bool, isPathMissing bool, worktree *models.Worktree) []string {
|
|
textStyle := theme.DefaultTextColor
|
|
|
|
current := ""
|
|
currentColor := style.FgCyan
|
|
if isCurrent {
|
|
current = " *"
|
|
currentColor = style.FgGreen
|
|
}
|
|
|
|
icon := icons.IconForWorktree(false)
|
|
if isPathMissing {
|
|
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 isPathMissing && !icons.IsIconEnabled() {
|
|
name += " " + tr.MissingWorktree
|
|
}
|
|
res = append(res, textStyle.Sprint(name))
|
|
return res
|
|
}
|