diff options
author | Matt Cles <matthew@cles.dev> | 2022-01-28 21:23:57 -0800 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-02-01 18:55:45 +1100 |
commit | 4df76466542441bceb6ebbb21a0730c5ea97e620 (patch) | |
tree | 93c98d1e32b95d2facb66947d00739e6b35e15d5 /pkg | |
parent | c7c4a375a98130e746af021fd706e354cf989d1f (diff) |
Add configurable colors for branch prefixes
Branches can now be colored based on their prefix, if it matches
a user defined prefix in the config file. If no user defined
prefix matches, then it will fallback to the defaults: green for
'feature', yellow for 'bugfix', and red for 'hotfix'. All
remaining branches will be set to the default text color.
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/config/user_config.go | 1 | ||||
-rw-r--r-- | pkg/gui/gui.go | 2 | ||||
-rw-r--r-- | pkg/gui/presentation/branches.go | 14 |
3 files changed, 17 insertions, 0 deletions
diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index a9977bdf6..9d7781358 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -25,6 +25,7 @@ type RefresherConfig struct { type GuiConfig struct { AuthorColors map[string]string `yaml:"authorColors"` + BranchColors map[string]string `yaml:"branchColors"` ScrollHeight int `yaml:"scrollHeight"` ScrollPastBottom bool `yaml:"scrollPastBottom"` MouseEvents bool `yaml:"mouseEvents"` diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 3549e186f..c0cb9692c 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -25,6 +25,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/gui/modes/diffing" "github.com/jesseduffield/lazygit/pkg/gui/modes/filtering" "github.com/jesseduffield/lazygit/pkg/gui/presentation/authors" + "github.com/jesseduffield/lazygit/pkg/gui/presentation" "github.com/jesseduffield/lazygit/pkg/gui/presentation/graph" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -492,6 +493,7 @@ func NewGui( gui.PopupHandler = &RealPopupHandler{gui: gui} authors.SetCustomAuthors(gui.UserConfig.Gui.AuthorColors) + presentation.SetCustomBranchColors(gui.UserConfig.Gui.BranchColors) return gui, nil } diff --git a/pkg/gui/presentation/branches.go b/pkg/gui/presentation/branches.go index c8a613516..50a4ef094 100644 --- a/pkg/gui/presentation/branches.go +++ b/pkg/gui/presentation/branches.go @@ -4,11 +4,14 @@ import ( "fmt" "strings" + "github.com/gookit/color" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/theme" ) +var branchPrefixColors = make(map[string]style.TextStyle) + func GetBranchListDisplayStrings(branches []*models.Branch, fullDescription bool, diffName string) [][]string { lines := make([][]string, len(branches)) @@ -58,6 +61,10 @@ func getBranchDisplayStrings(b *models.Branch, fullDescription bool, diffed bool func GetBranchTextStyle(name string) style.TextStyle { branchType := strings.Split(name, "/")[0] + if value, ok := branchPrefixColors[branchType]; ok { + return value + } + switch branchType { case "feature": return style.FgGreen @@ -84,3 +91,10 @@ func ColoredBranchStatus(branch *models.Branch) string { func BranchStatus(branch *models.Branch) string { return fmt.Sprintf("ā%sā%s", branch.Pushables, branch.Pullables) } + +func SetCustomBranchColors(customBranchColors map[string]string) { + for branchPrefix, colorSequence := range customBranchColors { + style := style.New().SetFg(style.NewRGBColor(color.HEX(colorSequence, false))) + branchPrefixColors[branchPrefix] = style + } +} |