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