Skip to content

Commit 47b4867

Browse files
authored
fix: reset colors on config read (#1309)
* fix: reset colors on config read * mention envs in docs for colors option
1 parent beae38f commit 47b4867

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

docs/mdbook/configuration/colors.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ colors:
2727
yellow: '#F0E68C'
2828
```
2929
30+
Control via ENV variable.
31+
32+
- Set `NO_COLOR=true` to disable colored output in lefthook and all subcommands that lefthook calls.
33+
- Set `CLICOLOR_FORCE=true` to force colored output in lefthook and all subcommands.

internal/command/lefthook.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ const (
3232
)
3333

3434
type Lefthook struct {
35-
fs afero.Fs
36-
repo *git.Repository
35+
fs afero.Fs
36+
repo *git.Repository
37+
colors string
3738
}
3839

3940
// NewLefthook returns an instance of Lefthook.
@@ -65,11 +66,16 @@ func NewLefthook(verbose bool, colors string) (*Lefthook, error) {
6566
return nil, err
6667
}
6768

68-
return &Lefthook{fs: fs, repo: repo}, nil
69+
return &Lefthook{fs: fs, repo: repo, colors: colors}, nil
6970
}
7071

7172
func (l *Lefthook) LoadConfig() (*config.Config, error) {
72-
return config.Load(l.fs, l.repo)
73+
cfg, err := config.Load(l.fs, l.repo)
74+
75+
// Reset colors
76+
log.SetColors(l.colors)
77+
78+
return cfg, err
7379
}
7480

7581
func (l *Lefthook) reloadConfig(cfg *config.Config) (*config.Config, error) {

internal/log/log.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ func SetColors(colors any) {
188188
switch typedColors {
189189
case "on":
190190
std.colors = ColorOn
191+
setColor(lipgloss.CompleteColor{TrueColor: "#ff6347", ANSI256: "196", ANSI: "9"}, &ColorRed)
192+
setColor(lipgloss.CompleteColor{TrueColor: "#32cd32", ANSI256: "148", ANSI: "2"}, &ColorGreen)
193+
setColor(lipgloss.CompleteColor{TrueColor: "#fada5e", ANSI256: "191", ANSI: "11"}, &ColorYellow)
194+
setColor(lipgloss.CompleteColor{TrueColor: "#70C0BA", ANSI256: "37", ANSI: "14"}, &ColorCyan)
195+
setColor(lipgloss.CompleteColor{TrueColor: "#808080", ANSI256: "244", ANSI: "7"}, &GolorGray)
196+
setColor(lipgloss.Color("#383838"), &colorBorder)
191197
case "off":
192198
std.colors = ColorOff
193199
setColor(lipgloss.NoColor{}, &ColorRed)
@@ -235,6 +241,8 @@ func setColor(colorCode any, adaptiveColor *lipgloss.TerminalColor) {
235241
case lipgloss.NoColor:
236242
*adaptiveColor = typedCode
237243
return
244+
case lipgloss.TerminalColor:
245+
*adaptiveColor = typedCode
238246
default:
239247
return
240248
}

0 commit comments

Comments
 (0)