Skip to content

Commit c47c539

Browse files
committed
support user-configurable author colours
1 parent c96496c commit c47c539

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

docs/Config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ gui:
5050
showRandomTip: true
5151
showCommandLog: true
5252
commandLogSize: 8
53+
authorColors: # in case you're not happy with the randomly assigned colour
54+
'John Smith': '#ff0000'
5355
git:
5456
paging:
5557
colorArg: always

pkg/config/user_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type RefresherConfig struct {
2424
}
2525

2626
type GuiConfig struct {
27+
AuthorColors map[string]string `yaml:"authorColors"`
2728
ScrollHeight int `yaml:"scrollHeight"`
2829
ScrollPastBottom bool `yaml:"scrollPastBottom"`
2930
MouseEvents bool `yaml:"mouseEvents"`

pkg/gui/gui.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking"
2323
"github.com/jesseduffield/lazygit/pkg/gui/modes/diffing"
2424
"github.com/jesseduffield/lazygit/pkg/gui/modes/filtering"
25+
"github.com/jesseduffield/lazygit/pkg/gui/presentation/authors"
2526
"github.com/jesseduffield/lazygit/pkg/gui/style"
2627
"github.com/jesseduffield/lazygit/pkg/gui/types"
2728
"github.com/jesseduffield/lazygit/pkg/i18n"
@@ -452,6 +453,8 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom
452453
oSCommand.SetOnRunCommand(onRunCommand)
453454
gui.OnRunCommand = onRunCommand
454455

456+
authors.SetCustomAuthors(gui.Config.GetUserConfig().Gui.AuthorColors)
457+
455458
return gui, nil
456459
}
457460

pkg/gui/presentation/authors/authors.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/mattn/go-runewidth"
1212
)
1313

14+
// if these being global variables causes trouble we can wrap them in a struct
15+
// attached to the gui state.
1416
var authorInitialCache = make(map[string]string)
1517
var authorNameCache = make(map[string]string)
1618
var authorStyleCache = make(map[string]style.TextStyle)
@@ -101,3 +103,10 @@ func getFirstRune(str string) rune {
101103
// should never land here
102104
return 0
103105
}
106+
107+
func SetCustomAuthors(customAuthorColors map[string]string) {
108+
for authorName, colorSequence := range customAuthorColors {
109+
style := style.New().SetFg(style.NewRGBColor(color.HEX(colorSequence, false)))
110+
authorStyleCache[authorName] = style
111+
}
112+
}

0 commit comments

Comments
 (0)