mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
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.
This commit is contained in:
parent
c7c4a375a9
commit
4df7646654
@ -400,6 +400,16 @@ gui:
|
|||||||
'*': '#0000ff'
|
'*': '#0000ff'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Custom Branch Color
|
||||||
|
|
||||||
|
You can customize the color of branches based on the branch prefix:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
gui:
|
||||||
|
branchColors:
|
||||||
|
'docs': '#11aaff' # use a light blue for branches beginning with 'docs/'
|
||||||
|
```
|
||||||
|
|
||||||
## Example Coloring
|
## Example Coloring
|
||||||
|
|
||||||
![border example](../../assets/colored-border-example.png)
|
![border example](../../assets/colored-border-example.png)
|
||||||
|
@ -25,6 +25,7 @@ type RefresherConfig struct {
|
|||||||
|
|
||||||
type GuiConfig struct {
|
type GuiConfig struct {
|
||||||
AuthorColors map[string]string `yaml:"authorColors"`
|
AuthorColors map[string]string `yaml:"authorColors"`
|
||||||
|
BranchColors map[string]string `yaml:"branchColors"`
|
||||||
ScrollHeight int `yaml:"scrollHeight"`
|
ScrollHeight int `yaml:"scrollHeight"`
|
||||||
ScrollPastBottom bool `yaml:"scrollPastBottom"`
|
ScrollPastBottom bool `yaml:"scrollPastBottom"`
|
||||||
MouseEvents bool `yaml:"mouseEvents"`
|
MouseEvents bool `yaml:"mouseEvents"`
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
|
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/modes/filtering"
|
"github.com/jesseduffield/lazygit/pkg/gui/modes/filtering"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/presentation/authors"
|
"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/presentation/graph"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
@ -492,6 +493,7 @@ func NewGui(
|
|||||||
gui.PopupHandler = &RealPopupHandler{gui: gui}
|
gui.PopupHandler = &RealPopupHandler{gui: gui}
|
||||||
|
|
||||||
authors.SetCustomAuthors(gui.UserConfig.Gui.AuthorColors)
|
authors.SetCustomAuthors(gui.UserConfig.Gui.AuthorColors)
|
||||||
|
presentation.SetCustomBranchColors(gui.UserConfig.Gui.BranchColors)
|
||||||
|
|
||||||
return gui, nil
|
return gui, nil
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gookit/color"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||||
"github.com/jesseduffield/lazygit/pkg/theme"
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var branchPrefixColors = make(map[string]style.TextStyle)
|
||||||
|
|
||||||
func GetBranchListDisplayStrings(branches []*models.Branch, fullDescription bool, diffName string) [][]string {
|
func GetBranchListDisplayStrings(branches []*models.Branch, fullDescription bool, diffName string) [][]string {
|
||||||
lines := make([][]string, len(branches))
|
lines := make([][]string, len(branches))
|
||||||
|
|
||||||
@ -58,6 +61,10 @@ func getBranchDisplayStrings(b *models.Branch, fullDescription bool, diffed bool
|
|||||||
func GetBranchTextStyle(name string) style.TextStyle {
|
func GetBranchTextStyle(name string) style.TextStyle {
|
||||||
branchType := strings.Split(name, "/")[0]
|
branchType := strings.Split(name, "/")[0]
|
||||||
|
|
||||||
|
if value, ok := branchPrefixColors[branchType]; ok {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
switch branchType {
|
switch branchType {
|
||||||
case "feature":
|
case "feature":
|
||||||
return style.FgGreen
|
return style.FgGreen
|
||||||
@ -84,3 +91,10 @@ func ColoredBranchStatus(branch *models.Branch) string {
|
|||||||
func BranchStatus(branch *models.Branch) string {
|
func BranchStatus(branch *models.Branch) string {
|
||||||
return fmt.Sprintf("↑%s↓%s", branch.Pushables, branch.Pullables)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user