1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-25 12:24:47 +02:00
This commit is contained in:
Jesse Duffield 2023-07-16 11:45:08 +10:00
parent 7682ec029b
commit e8ec41fb0f
4 changed files with 25 additions and 14 deletions

View File

@ -4,7 +4,6 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/presentation" "github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/samber/lo"
) )
type WorktreesContext struct { type WorktreesContext struct {
@ -23,12 +22,11 @@ func NewWorktreesContext(c *ContextCommon) *WorktreesContext {
) )
getDisplayStrings := func(startIdx int, length int) [][]string { getDisplayStrings := func(startIdx int, length int) [][]string {
return lo.Map(c.Model().Worktrees, func(worktree *models.Worktree, _ int) []string { return presentation.GetWorktreeDisplayStrings(
return presentation.GetWorktreeDisplayString( c.Model().Worktrees,
c.Git().Worktree.IsCurrentWorktree(worktree), c.Git().Worktree.IsCurrentWorktree,
c.Git().Worktree.IsWorktreePathMissing(worktree), c.Git().Worktree.IsWorktreePathMissing,
worktree) )
})
} }
return &WorktreesContext{ return &WorktreesContext{

View File

@ -12,6 +12,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/jesseduffield/lazygit/pkg/theme" "github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo"
) )
var branchPrefixColorCache = make(map[string]style.TextStyle) var branchPrefixColorCache = make(map[string]style.TextStyle)
@ -49,6 +50,10 @@ func getBranchDisplayStrings(
coloredName := nameTextStyle.Sprint(displayName) coloredName := nameTextStyle.Sprint(displayName)
branchStatus := utils.WithPadding(ColoredBranchStatus(b, tr), 2, utils.AlignLeft) branchStatus := utils.WithPadding(ColoredBranchStatus(b, tr), 2, utils.AlignLeft)
if b.CheckedOutByOtherWorktree {
worktreeIcon := lo.Ternary(icons.IsIconEnabled(), icons.LINKED_WORKTREE_ICON, "(worktree)")
coloredName = fmt.Sprintf("%s %s", coloredName, style.FgDefault.Sprint(worktreeIcon))
}
coloredName = fmt.Sprintf("%s %s", coloredName, branchStatus) coloredName = fmt.Sprintf("%s %s", coloredName, branchStatus)
recencyColor := style.FgCyan recencyColor := style.FgCyan
@ -58,6 +63,7 @@ func getBranchDisplayStrings(
res := make([]string, 0, 6) res := make([]string, 0, 6)
res = append(res, recencyColor.Sprint(b.Recency)) res = append(res, recencyColor.Sprint(b.Recency))
if icons.IsIconEnabled() { if icons.IsIconEnabled() {
res = append(res, nameTextStyle.Sprint(icons.IconForBranch(b))) res = append(res, nameTextStyle.Sprint(icons.IconForBranch(b)))
} }

View File

@ -71,10 +71,7 @@ func IconForStash(stash *models.StashEntry) string {
return STASH_ICON return STASH_ICON
} }
func IconForWorktree(worktree *models.Worktree, missing bool) string { func IconForWorktree(missing bool) string {
if worktree.Main() {
return ""
}
if missing { if missing {
return MISSING_LINKED_WORKTREE_ICON return MISSING_LINKED_WORKTREE_ICON
} }

View File

@ -5,8 +5,18 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons" "github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
"github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/theme" "github.com/jesseduffield/lazygit/pkg/theme"
"github.com/samber/lo"
) )
func GetWorktreeDisplayStrings(worktrees []*models.Worktree, isCurrent func(*models.Worktree) bool, isMissing func(*models.Worktree) bool) [][]string {
return lo.Map(worktrees, func(worktree *models.Worktree, _ int) []string {
return GetWorktreeDisplayString(
isCurrent(worktree),
isMissing(worktree),
worktree)
})
}
func GetWorktreeDisplayString(isCurrent bool, isPathMissing bool, worktree *models.Worktree) []string { func GetWorktreeDisplayString(isCurrent bool, isPathMissing bool, worktree *models.Worktree) []string {
textStyle := theme.DefaultTextColor textStyle := theme.DefaultTextColor
@ -17,13 +27,13 @@ func GetWorktreeDisplayString(isCurrent bool, isPathMissing bool, worktree *mode
currentColor = style.FgGreen currentColor = style.FgGreen
} }
icon := icons.IconForWorktree(worktree, false) icon := icons.IconForWorktree(false)
if isPathMissing { if isPathMissing {
textStyle = style.FgRed textStyle = style.FgRed
icon = icons.IconForWorktree(worktree, true) icon = icons.IconForWorktree(true)
} }
res := make([]string, 0, 3) res := []string{}
res = append(res, currentColor.Sprint(current)) res = append(res, currentColor.Sprint(current))
if icons.IsIconEnabled() { if icons.IsIconEnabled() {
res = append(res, textStyle.Sprint(icon)) res = append(res, textStyle.Sprint(icon))