Skip to content

Commit

Permalink
Add ability to configure branch color patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrajano committed Dec 30, 2024
1 parent a4ecd29 commit 95042fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions pkg/gui/presentation/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit 95042fb

Please sign in to comment.