1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-09 13:47:11 +02:00

Add shared function for loading map of custom colors

This commit is contained in:
Matt Cles 2022-01-31 21:23:55 -08:00 committed by Jesse Duffield
parent 4df7646654
commit 9adf4a1908
4 changed files with 20 additions and 14 deletions

View File

@ -24,8 +24,8 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking" "github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
"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" "github.com/jesseduffield/lazygit/pkg/gui/presentation"
"github.com/jesseduffield/lazygit/pkg/gui/presentation/authors"
"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"
@ -493,7 +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) presentation.SetCustomBranches(gui.UserConfig.Gui.BranchColors)
return gui, nil return gui, nil
} }

View File

@ -114,8 +114,5 @@ func getFirstRune(str string) rune {
} }
func SetCustomAuthors(customAuthorColors map[string]string) { func SetCustomAuthors(customAuthorColors map[string]string) {
for authorName, colorSequence := range customAuthorColors { authorStyleCache = utils.SetCustomColors(customAuthorColors)
style := style.New().SetFg(style.NewRGBColor(color.HEX(colorSequence, false)))
authorStyleCache[authorName] = style
}
} }

View File

@ -4,13 +4,13 @@ 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"
"github.com/jesseduffield/lazygit/pkg/utils"
) )
var branchPrefixColors = make(map[string]style.TextStyle) var branchPrefixColorCache = 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))
@ -61,7 +61,7 @@ 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 { if value, ok := branchPrefixColorCache[branchType]; ok {
return value return value
} }
@ -92,9 +92,6 @@ 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) { func SetCustomBranches(customBranchColors map[string]string) {
for branchPrefix, colorSequence := range customBranchColors { branchPrefixColorCache = utils.SetCustomColors(customBranchColors)
style := style.New().SetFg(style.NewRGBColor(color.HEX(colorSequence, false)))
branchPrefixColors[branchPrefix] = style
}
} }

View File

@ -3,6 +3,9 @@ package utils
import ( import (
"regexp" "regexp"
"sync" "sync"
"github.com/gookit/color"
"github.com/jesseduffield/lazygit/pkg/gui/style"
) )
var decoloriseCache = make(map[string]string) var decoloriseCache = make(map[string]string)
@ -48,3 +51,12 @@ func IsValidHexValue(v string) bool {
return true return true
} }
func SetCustomColors(customColors map[string]string) map[string]style.TextStyle {
colors := make(map[string]style.TextStyle)
for key, colorSequence := range customColors {
style := style.New().SetFg(style.NewRGBColor(color.HEX(colorSequence, false)))
colors[key] = style
}
return colors
}