jesseduffield.lazygit/pkg/gui/presentation/remote_branches.go
2026-09-04 20:37:01 +08:00

43 lines
1.2 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/theme"
"github.com/samber/lo"
)
func GetRemoteBranchListDisplayStrings(branches []*models.RemoteBranch, diffName string) [][]string {
return lo.Map(branches, func(branch *models.RemoteBranch, _ int) []string {
diffed := branch.FullName() == diffName
return getRemoteBranchDisplayStrings(branch, diffed)
})
}
// getRemoteBranchDisplayStrings returns the display string of branch
func getRemoteBranchDisplayStrings(b *models.RemoteBranch, diffed bool) []string {
textStyle := GetBranchTextStyle(b.Name)
if diffed {
textStyle = theme.DiffTerminalColor
}
name := b.Name
// SVN stale 标记
switch b.StaleStatus {
case models.SvnBranchStatusStale:
name = b.Name + "⚠"
textStyle = style.FgRed
case models.SvnBranchStatusMissing:
name = b.Name + "(not fetched)"
textStyle = style.FgWhite
}
res := make([]string, 0, 2)
if icons.IsIconEnabled() {
res = append(res, textStyle.Sprint(icons.IconForRemoteBranch(b)))
}
res = append(res, textStyle.Sprint(name))
return res
}