Skip to content

Commit 0d7ed57

Browse files
authored
feat: allow customization of log indicator toggles closes derailed#2024 (derailed#2041)
1 parent 3526094 commit 0d7ed57

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,13 @@ k9s:
866866
valueColor: royalblue
867867
# Logs styles.
868868
logs:
869-
fgColor: white
869+
fgColor: lightskyblue
870870
bgColor: black
871+
indicator:
872+
fgColor: dodgerblue
873+
bgColor: black
874+
toggleOnColor: limegreen
875+
toggleOffColor: gray
871876
```
872877

873878
---

internal/config/styles.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ type (
121121

122122
// LogIndicator tracks log view indicator.
123123
LogIndicator struct {
124-
FgColor Color `yaml:"fgColor"`
125-
BgColor Color `yaml:"bgColor"`
124+
FgColor Color `yaml:"fgColor"`
125+
BgColor Color `yaml:"bgColor"`
126+
ToggleOnColor Color `yaml:"toggleOnColor"`
127+
ToggleOffColor Color `yaml:"toggleOffColor"`
126128
}
127129

128130
// Yaml tracks yaml styles.
@@ -367,8 +369,10 @@ func newLog() Log {
367369

368370
func newLogIndicator() LogIndicator {
369371
return LogIndicator{
370-
FgColor: "dodgerblue",
371-
BgColor: "black",
372+
FgColor: "dodgerblue",
373+
BgColor: "black",
374+
ToggleOnColor: "limegreen",
375+
ToggleOffColor: "gray",
372376
}
373377
}
374378

internal/view/log_indicator.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package view
22

33
import (
4+
"fmt"
45
"sync/atomic"
56

67
"github.com/derailed/k9s/internal/config"
@@ -47,6 +48,7 @@ func NewLogIndicator(cfg *config.Config, styles *config.Styles, allContainers bo
4748
func (l *LogIndicator) StylesChanged(styles *config.Styles) {
4849
l.SetBackgroundColor(styles.K9s.Views.Log.Indicator.BgColor.Color())
4950
l.SetTextColor(styles.K9s.Views.Log.Indicator.FgColor.Color())
51+
l.Refresh()
5052
}
5153

5254
// AutoScroll reports the current scrolling status.
@@ -111,36 +113,39 @@ func (l *LogIndicator) reset() {
111113
func (l *LogIndicator) Refresh() {
112114
l.reset()
113115

116+
toggleOnFormat := "[::b]%s:[" + string(l.styles.K9s.Views.Log.Indicator.ToggleOnColor) + "::b]On[-::] %s"
117+
toggleOffFormat := "[::b]%s:[" + string(l.styles.K9s.Views.Log.Indicator.ToggleOffColor) + "::d]Off[-::]%s"
118+
114119
if l.shouldDisplayAllContainers {
115120
if l.allContainers {
116-
l.indicator = append(l.indicator, "[::b]AllContainers:[limegreen::b]On[-::] "+spacer...)
121+
l.indicator = append(l.indicator, fmt.Sprintf(toggleOnFormat, "AllContainers", spacer)...)
117122
} else {
118-
l.indicator = append(l.indicator, "[::b]AllContainers:[gray::d]Off[-::]"+spacer...)
123+
l.indicator = append(l.indicator, fmt.Sprintf(toggleOffFormat, "AllContainers", spacer)...)
119124
}
120125
}
121126

122127
if l.AutoScroll() {
123-
l.indicator = append(l.indicator, "[::b]Autoscroll:[limegreen::b]On[-::] "+spacer...)
128+
l.indicator = append(l.indicator, fmt.Sprintf(toggleOnFormat, "Autoscroll", spacer)...)
124129
} else {
125-
l.indicator = append(l.indicator, "[::b]Autoscroll:[gray::d]Off[-::]"+spacer...)
130+
l.indicator = append(l.indicator, fmt.Sprintf(toggleOffFormat, "Autoscroll", spacer)...)
126131
}
127132

128133
if l.FullScreen() {
129-
l.indicator = append(l.indicator, "[::b]FullScreen:[limegreen::b]On[-::] "+spacer...)
134+
l.indicator = append(l.indicator, fmt.Sprintf(toggleOnFormat, "FullScreen", spacer)...)
130135
} else {
131-
l.indicator = append(l.indicator, "[::b]FullScreen:[gray::d]Off[-::]"+spacer...)
136+
l.indicator = append(l.indicator, fmt.Sprintf(toggleOffFormat, "FullScreen", spacer)...)
132137
}
133138

134139
if l.Timestamp() {
135-
l.indicator = append(l.indicator, "[::b]Timestamps:[limegreen::b]On[-::] "+spacer...)
140+
l.indicator = append(l.indicator, fmt.Sprintf(toggleOnFormat, "Timestamps", spacer)...)
136141
} else {
137-
l.indicator = append(l.indicator, "[::b]Timestamps:[gray::d]Off[-::]"+spacer...)
142+
l.indicator = append(l.indicator, fmt.Sprintf(toggleOffFormat, "Timestamps", spacer)...)
138143
}
139144

140145
if l.TextWrap() {
141-
l.indicator = append(l.indicator, "[::b]Wrap:[limegreen::b]On[-::] "...)
146+
l.indicator = append(l.indicator, fmt.Sprintf(toggleOnFormat, "Wrap", "")...)
142147
} else {
143-
l.indicator = append(l.indicator, "[::b]Wrap:[gray::d]Off[-::]"...)
148+
l.indicator = append(l.indicator, fmt.Sprintf(toggleOffFormat, "Wrap", "")...)
144149
}
145150

146151
_, _ = l.Write(l.indicator)

0 commit comments

Comments
 (0)