diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 1c3d9e35061..88c84c0ef36 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -11,6 +11,7 @@ import ( "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" "github.com/jesseduffield/lazygit/pkg/gui/presentation/icons" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -251,42 +252,12 @@ func stateText(state string) string { 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, "")) + presentation.WithPrColor(state, "", false), + presentation.WithPrColor(state, color.RGB(0xFF, 0xFF, 0xFF, false).Sprint(stateText(state)), true), + presentation.WithPrColor(state, "", false)) } - 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) - } + return presentation.WithPrColor(state, stateText(state), false) } func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branch) error { diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go index f406547bc82..995d0208d83 100644 --- a/pkg/gui/presentation/branches.go +++ b/pkg/gui/presentation/branches.go @@ -6,6 +6,7 @@ import ( "strings" "time" + "github.com/gookit/color" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/config" @@ -148,7 +149,7 @@ func getBranchDisplayStrings( } else { prIcon = "●" } - coloredPrIcon = prColor(pr.State).Sprint(prIcon) + coloredPrIcon = WithPrColor(pr.State, prIcon, false) } res = append(res, coloredPrIcon) @@ -271,17 +272,17 @@ func SetCustomBranches(customBranchColors map[string]string, isRegex bool) { } } -func prColor(state string) style.TextStyle { +func WithPrColor(state string, text string, isBg bool) string { switch state { case "OPEN": - return style.FgGreen + return color.RGB(0x43, 0x84, 0x40, isBg).Sprint(text) case "CLOSED": - return style.FgRed + return color.RGB(0xC9, 0x45, 0x3C, isBg).Sprint(text) case "MERGED": - return style.FgMagenta + return color.RGB(0x82, 0x59, 0xDD, isBg).Sprint(text) case "DRAFT": - return style.FgBlackLighter + return color.RGB(0x67, 0x6C, 0x75, isBg).Sprint(text) default: - return style.FgDefault + return lo.Ternary(isBg, style.BgDefault, style.FgDefault).Sprint(text) } }