Skip to content

Commit ddf1f4b

Browse files
Resources-are-rendered-using-skin.yaml-colors
1 parent dc06add commit ddf1f4b

33 files changed

+149
-239
lines changed

README.md

-5
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ K9s is available on Linux, macOS and Windows platforms.
7575
pkg install k9s
7676
```
7777

78-
* Via [Winget](https://github.com/microsoft/winget-cli) for Windows
79-
```shell
80-
winget install k9s
81-
```
82-
8378
* Via [Scoop](https://scoop.sh) for Windows
8479

8580
```shell

internal/config/styles.go

+37-14
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ type (
6161

6262
// Body tracks body styles.
6363
Body struct {
64-
FgColor Color `yaml:"fgColor"`
65-
BgColor Color `yaml:"bgColor"`
66-
LogoColor Color `yaml:"logoColor"`
67-
LogoColorMsg Color `yaml:"logoColorMsg"`
68-
LogoColorInfo Color `yaml:"logoColorInfo"`
69-
LogoColorWarn Color `yaml:"logoColorWarn"`
70-
LogoColorError Color `yaml:"logoColorError"`
64+
FgColor Color `yaml:"fgColor"`
65+
BgColor Color `yaml:"bgColor"`
66+
LogoColor Color `yaml:"logoColor"`
67+
LogoColorMsg Color `yaml:"logoColorMsg"`
68+
LogoColorInfo Color `yaml:"logoColorInfo"`
69+
LogoColorWarn Color `yaml:"logoColorWarn"`
70+
LogoColorError Color `yaml:"logoColorError"`
71+
FlashColorOk Color `yaml:"flashColorOk"`
72+
FlashColorWarn Color `yaml:"flashColorWarn"`
73+
FlashColorError Color `yaml:"flashColorError"`
7174
}
7275

7376
// Dialog tracks dialog styles.
@@ -80,6 +83,7 @@ type (
8083
ButtonFocusBgColor Color `yaml:"buttonFocusBgColor"`
8184
LabelFgColor Color `yaml:"labelFgColor"`
8285
FieldFgColor Color `yaml:"fieldFgColor"`
86+
ErrorColor Color `yaml:"errorColor"`
8387
}
8488

8589
// Frame tracks frame styles.
@@ -279,6 +283,7 @@ func newDialog() Dialog {
279283
ButtonFocusFgColor: "black",
280284
LabelFgColor: "white",
281285
FieldFgColor: "white",
286+
ErrorColor: "orangered",
282287
}
283288
}
284289

@@ -336,13 +341,16 @@ func newHelp() Help {
336341

337342
func newBody() Body {
338343
return Body{
339-
FgColor: "cadetblue",
340-
BgColor: "black",
341-
LogoColor: "orange",
342-
LogoColorMsg: "white",
343-
LogoColorInfo: "green",
344-
LogoColorWarn: "mediumvioletred",
345-
LogoColorError: "red",
344+
FgColor: "cadetblue",
345+
BgColor: "black",
346+
LogoColor: "orange",
347+
LogoColorMsg: "white",
348+
LogoColorInfo: "green",
349+
LogoColorWarn: "mediumvioletred",
350+
LogoColorError: "red",
351+
FlashColorOk: "green",
352+
FlashColorWarn: "yellow",
353+
FlashColorError: "red",
346354
}
347355
}
348356

@@ -480,6 +488,21 @@ func (s *Styles) BgColor() tcell.Color {
480488
return s.Body().BgColor.Color()
481489
}
482490

491+
// FlashColorOk returns the color in combination with happy emoji.
492+
func (s *Styles) FlashColorOk() tcell.Color {
493+
return s.Body().FlashColorOk.Color()
494+
}
495+
496+
// FlashColorWarn returns the color in combination with warn emoji.
497+
func (s *Styles) FlashColorWarn() tcell.Color {
498+
return s.Body().FlashColorWarn.Color()
499+
}
500+
501+
// FlashColorWarn returns the color in combination with angry emoji.
502+
func (s *Styles) FlashColorError() tcell.Color {
503+
return s.Body().FlashColorError.Color()
504+
}
505+
483506
// AddListener registers a new listener.
484507
func (s *Styles) AddListener(l StyleListener) {
485508
s.listeners = append(s.listeners, l)

internal/render/benchmark.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"strings"
1010

1111
"github.com/derailed/k9s/internal/client"
12-
"github.com/derailed/tcell/v2"
1312
"github.com/derailed/tview"
1413
"k8s.io/apimachinery/pkg/runtime"
1514
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -30,12 +29,7 @@ type Benchmark struct {
3029

3130
// ColorerFunc colors a resource row.
3231
func (b Benchmark) ColorerFunc() ColorerFunc {
33-
return func(ns string, h Header, re RowEvent) tcell.Color {
34-
if !Happy(ns, h, re.Row) {
35-
return ErrColor
36-
}
37-
return tcell.ColorPaleGreen
38-
}
32+
return DefaultColorer
3933
}
4034

4135
// Header returns a header row.

internal/render/dir.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"os"
66

7-
"github.com/derailed/tcell/v2"
87
"k8s.io/apimachinery/pkg/runtime"
98
"k8s.io/apimachinery/pkg/runtime/schema"
109
)
@@ -19,9 +18,7 @@ func (Dir) IsGeneric() bool {
1918

2019
// ColorerFunc colors a resource row.
2120
func (Dir) ColorerFunc() ColorerFunc {
22-
return func(ns string, _ Header, re RowEvent) tcell.Color {
23-
return tcell.ColorCadetBlue
24-
}
21+
return DefaultColorer
2522
}
2623

2724
// Header returns a header row.

internal/render/helm.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"strconv"
66

77
"github.com/derailed/k9s/internal/client"
8-
"github.com/derailed/tcell/v2"
98
"helm.sh/helm/v3/pkg/release"
109
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1110
"k8s.io/apimachinery/pkg/runtime"
@@ -22,13 +21,7 @@ func (Helm) IsGeneric() bool {
2221

2322
// ColorerFunc colors a resource row.
2423
func (Helm) ColorerFunc() ColorerFunc {
25-
return func(ns string, h Header, re RowEvent) tcell.Color {
26-
if !Happy(ns, h, re.Row) {
27-
return ErrColor
28-
}
29-
30-
return tcell.ColorMediumSpringGreen
31-
}
24+
return DefaultColorer
3225
}
3326

3427
// Header returns a header row.

internal/render/policy.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
"github.com/derailed/k9s/internal/client"
7-
"github.com/derailed/tcell/v2"
87
"github.com/rs/zerolog/log"
98
"k8s.io/apimachinery/pkg/runtime"
109
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -31,9 +30,7 @@ type Policy struct {
3130

3231
// ColorerFunc colors a resource row.
3332
func (Policy) ColorerFunc() ColorerFunc {
34-
return func(ns string, _ Header, re RowEvent) tcell.Color {
35-
return tcell.ColorMediumSpringGreen
36-
}
33+
return DefaultColorer
3734
}
3835

3936
// Header returns a header row.

internal/render/portforward.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"strings"
66

77
"github.com/derailed/k9s/internal/client"
8-
"github.com/derailed/tcell/v2"
98
"k8s.io/apimachinery/pkg/runtime"
109
"k8s.io/apimachinery/pkg/runtime/schema"
1110
)
@@ -35,9 +34,7 @@ type PortForward struct {
3534

3635
// ColorerFunc colors a resource row.
3736
func (PortForward) ColorerFunc() ColorerFunc {
38-
return func(ns string, _ Header, re RowEvent) tcell.Color {
39-
return tcell.ColorSkyblue
40-
}
37+
return DefaultColorer
4138
}
4239

4340
// Header returns a header row.

internal/render/reference.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55

66
"github.com/derailed/k9s/internal/client"
7-
"github.com/derailed/tcell/v2"
87
"k8s.io/apimachinery/pkg/runtime"
98
"k8s.io/apimachinery/pkg/runtime/schema"
109
)
@@ -16,9 +15,7 @@ type Reference struct {
1615

1716
// ColorerFunc colors a resource row.
1817
func (Reference) ColorerFunc() ColorerFunc {
19-
return func(ns string, _ Header, re RowEvent) tcell.Color {
20-
return tcell.ColorCadetBlue
21-
}
18+
return DefaultColorer
2219
}
2320

2421
// Header returns a header row.

internal/render/screen_dump.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"path/filepath"
77
"time"
88

9-
"github.com/derailed/tcell/v2"
109
"k8s.io/apimachinery/pkg/runtime"
1110
"k8s.io/apimachinery/pkg/runtime/schema"
1211
)
@@ -18,9 +17,7 @@ type ScreenDump struct {
1817

1918
// ColorerFunc colors a resource row.
2019
func (ScreenDump) ColorerFunc() ColorerFunc {
21-
return func(ns string, _ Header, re RowEvent) tcell.Color {
22-
return tcell.ColorNavajoWhite
23-
}
20+
return DefaultColorer
2421
}
2522

2623
// Header returns a header row.

internal/render/subject.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package render
33
import (
44
"fmt"
55

6-
"github.com/derailed/tcell/v2"
76
"k8s.io/apimachinery/pkg/runtime"
87
"k8s.io/apimachinery/pkg/runtime/schema"
98
)
@@ -15,9 +14,7 @@ type Subject struct {
1514

1615
// ColorerFunc colors a resource row.
1716
func (Subject) ColorerFunc() ColorerFunc {
18-
return func(ns string, _ Header, re RowEvent) tcell.Color {
19-
return tcell.ColorMediumSpringGreen
20-
}
17+
return DefaultColorer
2118
}
2219

2320
// Header returns a header row.

internal/ui/dialog/error.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/derailed/k9s/internal/config"
88
"github.com/derailed/k9s/internal/ui"
9-
"github.com/derailed/tcell/v2"
109
"github.com/derailed/tview"
1110
)
1211

@@ -18,7 +17,7 @@ func ShowError(styles config.Dialog, pages *ui.Pages, msg string) {
1817
SetButtonBackgroundColor(styles.ButtonBgColor.Color()).
1918
SetButtonTextColor(styles.ButtonFgColor.Color()).
2019
SetLabelColor(styles.LabelFgColor.Color()).
21-
SetFieldTextColor(tcell.ColorIndianRed)
20+
SetFieldTextColor(styles.FieldFgColor.Color())
2221
f.AddButton("Dismiss", func() {
2322
dismiss(pages)
2423
})
@@ -29,7 +28,7 @@ func ShowError(styles config.Dialog, pages *ui.Pages, msg string) {
2928
f.SetFocus(0)
3029
modal := tview.NewModalForm("<error>", f)
3130
modal.SetText(cowTalk(msg))
32-
modal.SetTextColor(tcell.ColorOrangeRed)
31+
modal.SetTextColor(styles.ErrorColor.Color())
3332
modal.SetDoneFunc(func(int, string) {
3433
dismiss(pages)
3534
})

internal/ui/flash.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewFlash(app *App) *Flash {
3030
app: app,
3131
TextView: tview.NewTextView(),
3232
}
33-
f.SetTextColor(tcell.ColorAqua)
33+
3434
f.SetDynamicColors(true)
3535
f.SetTextAlign(tview.AlignCenter)
3636
f.SetBorderPadding(0, 0, 1, 1)
@@ -70,7 +70,7 @@ func (f *Flash) SetMessage(m model.LevelMessage) {
7070
f.Clear()
7171
return
7272
}
73-
f.SetTextColor(flashColor(m.Level))
73+
f.SetTextColor(f.flashColor(m.Level))
7474
f.SetText(f.flashEmoji(m.Level) + " " + m.Text)
7575
}
7676

@@ -98,14 +98,16 @@ func (f *Flash) flashEmoji(l model.FlashLevel) string {
9898

9999
// Helpers...
100100

101-
func flashColor(l model.FlashLevel) tcell.Color {
101+
func (f *Flash) flashColor(l model.FlashLevel) tcell.Color {
102+
styles := f.app.Styles
103+
102104
// nolint:exhaustive
103105
switch l {
104106
case model.FlashWarn:
105-
return tcell.ColorOrange
107+
return styles.FlashColorWarn()
106108
case model.FlashErr:
107-
return tcell.ColorOrangeRed
109+
return styles.FlashColorError()
108110
default:
109-
return tcell.ColorNavajoWhite
111+
return styles.FlashColorOk()
110112
}
111113
}

internal/ui/indicator.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/derailed/k9s/internal/config"
99
"github.com/derailed/k9s/internal/model"
1010
"github.com/derailed/k9s/internal/render"
11-
"github.com/derailed/tcell/v2"
1211
"github.com/derailed/tview"
1312
)
1413

@@ -30,7 +29,7 @@ func NewStatusIndicator(app *App, styles *config.Styles) *StatusIndicator {
3029
styles: styles,
3130
}
3231
s.SetTextAlign(tview.AlignCenter)
33-
s.SetTextColor(tcell.ColorWhite)
32+
s.SetTextColor(styles.FgColor())
3433
s.SetBackgroundColor(styles.BgColor())
3534
s.SetDynamicColors(true)
3635
styles.AddListener(&s)

internal/ui/table.go

-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func (t *Table) Init(ctx context.Context) {
7171
t.SetBorderPadding(0, 0, 1, 1)
7272
t.SetSelectable(true, false)
7373
t.SetSelectionChangedFunc(t.selectionChanged)
74-
t.SetBackgroundColor(tcell.ColorDefault)
7574
t.Select(1, 0)
7675
if cfg, ok := ctx.Value(internal.KeyViewConfig).(*config.CustomView); ok && cfg != nil {
7776
cfg.AddListener(t.GVR().String(), t)

internal/ui/tree.go

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func (t *Tree) Init(ctx context.Context) error {
4040
t.SetBorderAttributes(tcell.AttrBold)
4141
t.SetBorderPadding(0, 0, 1, 1)
4242
t.SetGraphics(true)
43-
t.SetGraphicsColor(tcell.ColorCadetBlue)
4443
t.SetInputCapture(t.keyboard)
4544

4645
return nil

internal/view/alias.go

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ func NewAlias(gvr client.GVR) ResourceViewer {
2222
a := Alias{
2323
ResourceViewer: NewBrowser(gvr),
2424
}
25-
a.GetTable().SetBorderFocusColor(tcell.ColorAliceBlue)
26-
a.GetTable().SetSelectedStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite).Background(tcell.ColorAliceBlue).Attributes(tcell.AttrNone))
2725
a.AddBindKeysFn(a.bindKeys)
2826
a.SetContextFn(a.aliasContext)
2927

internal/view/benchmark.go

-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/derailed/k9s/internal/config"
1212
"github.com/derailed/k9s/internal/perf"
1313
"github.com/derailed/k9s/internal/ui"
14-
"github.com/derailed/tcell/v2"
1514
)
1615

1716
// Benchmark represents a service benchmark results view.
@@ -24,8 +23,6 @@ func NewBenchmark(gvr client.GVR) ResourceViewer {
2423
b := Benchmark{
2524
ResourceViewer: NewBrowser(gvr),
2625
}
27-
b.GetTable().SetBorderFocusColor(tcell.ColorSeaGreen)
28-
b.GetTable().SetSelectedStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite).Background(tcell.ColorSeaGreen).Attributes(tcell.AttrNone))
2926
b.GetTable().SetSortCol(ageCol, true)
3027
b.SetContextFn(b.benchContext)
3128
b.GetTable().SetEnterFn(b.viewBench)

0 commit comments

Comments
 (0)