From 95042fb92efa6534206e9ed596f865af098a5ae8 Mon Sep 17 00:00:00 2001 From: Mauricio Trajano Date: Thu, 26 Dec 2024 20:30:44 -0500 Subject: [PATCH] Add ability to configure branch color patterns --- docs/Config.md | 1 + pkg/gui/presentation/branches.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/docs/Config.md b/docs/Config.md index c64e56d2edf..7c9d142c832 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -814,6 +814,7 @@ You can customize the color of branches based on the branch prefix: gui: branchColors: 'docs': '#11aaff' # use a light blue for branches beginning with 'docs/' + 'ISSUE-*': '#ff5733' # use a bright orange for branches beginning with 'ISSUE-' ``` ## Example Coloring diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go index b75dfc95b72..bc4e7e6bb18 100644 --- a/pkg/gui/presentation/branches.go +++ b/pkg/gui/presentation/branches.go @@ -123,6 +123,19 @@ func getBranchDisplayStrings( return res } +func matchColorPrefix(name string) (style.TextStyle, bool) { + for possiblePattern, color := range branchPrefixColorCache { + if strings.Contains(possiblePattern, "*") { + prefix := strings.TrimSuffix(possiblePattern, "*") + if strings.HasPrefix(name, prefix) { + return color, true + } + } + } + + return style.TextStyle{}, false +} + // GetBranchTextStyle branch color func GetBranchTextStyle(name string) style.TextStyle { branchType := strings.Split(name, "/")[0] @@ -131,6 +144,10 @@ func GetBranchTextStyle(name string) style.TextStyle { return value } + if value, ok := matchColorPrefix(name); ok { + return value + } + switch branchType { case "feature": return style.FgGreen