diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index c796e19ab..f8a8d7c90 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -3,12 +3,16 @@ package controllers import ( "errors" "fmt" + "strings" + "github.com/gookit/color" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" + "github.com/jesseduffield/lazygit/pkg/gui/presentation/icons" + "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" @@ -192,7 +196,19 @@ func (self *BranchesController) GetOnRenderToMain() func() { } else { cmdObj := self.c.Git().Branch.GetGraphCmdObj(branch.FullRefName()) - task = types.NewRunPtyTask(cmdObj.GetCmd()) + ptyTask := types.NewRunPtyTask(cmdObj.GetCmd()) + task = ptyTask + + if pr, ok := self.c.Model().PullRequestsMap[branch.Name]; ok { + icon := lo.Ternary(icons.IsIconEnabled(), icons.IconForRemoteUrl(pr.Url)+" ", "") + ptyTask.Prefix = style.PrintHyperlink(fmt.Sprintf("%s%s %s %s\n", + icon, + coloredStateText(pr.State), + pr.Title, + style.FgCyan.Sprintf("#%d", pr.Number)), + pr.Url) + ptyTask.Prefix += strings.Repeat("─", self.c.Contexts().Normal.GetView().InnerWidth()) + "\n" + } } self.c.RenderToMainViews(types.RefreshMainOpts{ @@ -206,6 +222,67 @@ func (self *BranchesController) GetOnRenderToMain() func() { } } +func stateText(state string) string { + var icon, label string + switch state { + case "OPEN": + icon, label = " ", "Open" + case "CLOSED": + icon, label = " ", "Closed" + case "MERGED": + icon, label = " ", "Merged" + case "DRAFT": + icon, label = " ", "Draft" + default: + return "" + } + if icons.IsIconEnabled() { + return icon + label + } + return label +} + +func coloredStateText(state string) string { + if icons.IsIconEnabled() { + return fmt.Sprintf("%s%s%s", + withPrFgColor(state, ""), + withPrBgColor(state, style.FgWhite.Sprint(stateText(state))), + withPrFgColor(state, "")) + } + + return withPrFgColor(state, stateText(state)) +} + +func withPrFgColor(state string, text string) string { + switch state { + case "OPEN": + return style.FgGreen.Sprint(text) + case "CLOSED": + return style.FgRed.Sprint(text) + case "MERGED": + return style.FgMagenta.Sprint(text) + case "DRAFT": + return color.RGB(0x66, 0x66, 0x66, false).Sprint(text) + default: + return style.FgDefault.Sprint(text) + } +} + +func withPrBgColor(state string, text string) string { + switch state { + case "OPEN": + return style.BgGreen.Sprint(text) + case "CLOSED": + return style.BgRed.Sprint(text) + case "MERGED": + return style.BgMagenta.Sprint(text) + case "DRAFT": + return color.RGB(0x66, 0x66, 0x66, true).Sprint(text) + default: + return style.BgDefault.Sprint(text) + } +} + func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branch) error { upstream := lo.Ternary(selectedBranch.RemoteBranchStoredLocally(), selectedBranch.ShortUpstreamRefName(),