Skip to content

Commit

Permalink
support user-configurable author colours
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Oct 30, 2021
1 parent c96496c commit c47c539
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ gui:
showRandomTip: true
showCommandLog: true
commandLogSize: 8
authorColors: # in case you're not happy with the randomly assigned colour
'John Smith': '#ff0000'
git:
paging:
colorArg: always
Expand Down
1 change: 1 addition & 0 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type RefresherConfig struct {
}

type GuiConfig struct {
AuthorColors map[string]string `yaml:"authorColors"`
ScrollHeight int `yaml:"scrollHeight"`
ScrollPastBottom bool `yaml:"scrollPastBottom"`
MouseEvents bool `yaml:"mouseEvents"`
Expand Down
3 changes: 3 additions & 0 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
"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/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/i18n"
Expand Down Expand Up @@ -452,6 +453,8 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom
oSCommand.SetOnRunCommand(onRunCommand)
gui.OnRunCommand = onRunCommand

authors.SetCustomAuthors(gui.Config.GetUserConfig().Gui.AuthorColors)

return gui, nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/gui/presentation/authors/authors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/mattn/go-runewidth"
)

// if these being global variables causes trouble we can wrap them in a struct
// attached to the gui state.
var authorInitialCache = make(map[string]string)
var authorNameCache = make(map[string]string)
var authorStyleCache = make(map[string]style.TextStyle)
Expand Down Expand Up @@ -101,3 +103,10 @@ func getFirstRune(str string) rune {
// should never land here
return 0
}

func SetCustomAuthors(customAuthorColors map[string]string) {
for authorName, colorSequence := range customAuthorColors {
style := style.New().SetFg(style.NewRGBColor(color.HEX(colorSequence, false)))
authorStyleCache[authorName] = style
}
}

0 comments on commit c47c539

Please sign in to comment.