Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resources are rendered using skin.yaml colors #2089

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 37 additions & 14 deletions internal/config/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,16 @@ type (

// Body tracks body styles.
Body struct {
FgColor Color `yaml:"fgColor"`
BgColor Color `yaml:"bgColor"`
LogoColor Color `yaml:"logoColor"`
LogoColorMsg Color `yaml:"logoColorMsg"`
LogoColorInfo Color `yaml:"logoColorInfo"`
LogoColorWarn Color `yaml:"logoColorWarn"`
LogoColorError Color `yaml:"logoColorError"`
FgColor Color `yaml:"fgColor"`
BgColor Color `yaml:"bgColor"`
LogoColor Color `yaml:"logoColor"`
LogoColorMsg Color `yaml:"logoColorMsg"`
LogoColorInfo Color `yaml:"logoColorInfo"`
LogoColorWarn Color `yaml:"logoColorWarn"`
LogoColorError Color `yaml:"logoColorError"`
FlashColorOk Color `yaml:"flashColorOk"`
FlashColorWarn Color `yaml:"flashColorWarn"`
FlashColorError Color `yaml:"flashColorError"`
}

// Dialog tracks dialog styles.
Expand All @@ -80,6 +83,7 @@ type (
ButtonFocusBgColor Color `yaml:"buttonFocusBgColor"`
LabelFgColor Color `yaml:"labelFgColor"`
FieldFgColor Color `yaml:"fieldFgColor"`
ErrorColor Color `yaml:"errorColor"`
}

// Frame tracks frame styles.
Expand Down Expand Up @@ -279,6 +283,7 @@ func newDialog() Dialog {
ButtonFocusFgColor: "black",
LabelFgColor: "white",
FieldFgColor: "white",
ErrorColor: "orangered",
}
}

Expand Down Expand Up @@ -336,13 +341,16 @@ func newHelp() Help {

func newBody() Body {
return Body{
FgColor: "cadetblue",
BgColor: "black",
LogoColor: "orange",
LogoColorMsg: "white",
LogoColorInfo: "green",
LogoColorWarn: "mediumvioletred",
LogoColorError: "red",
FgColor: "cadetblue",
BgColor: "black",
LogoColor: "orange",
LogoColorMsg: "white",
LogoColorInfo: "green",
LogoColorWarn: "mediumvioletred",
LogoColorError: "red",
FlashColorOk: "green",
FlashColorWarn: "yellow",
FlashColorError: "red",
}
}

Expand Down Expand Up @@ -480,6 +488,21 @@ func (s *Styles) BgColor() tcell.Color {
return s.Body().BgColor.Color()
}

// FlashColorOk returns the color in combination with happy emoji.
func (s *Styles) FlashColorOk() tcell.Color {
return s.Body().FlashColorOk.Color()
}

// FlashColorWarn returns the color in combination with warn emoji.
func (s *Styles) FlashColorWarn() tcell.Color {
return s.Body().FlashColorWarn.Color()
}

// FlashColorWarn returns the color in combination with angry emoji.
func (s *Styles) FlashColorError() tcell.Color {
return s.Body().FlashColorError.Color()
}

// AddListener registers a new listener.
func (s *Styles) AddListener(l StyleListener) {
s.listeners = append(s.listeners, l)
Expand Down
8 changes: 1 addition & 7 deletions internal/render/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"

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

// ColorerFunc colors a resource row.
func (b Benchmark) ColorerFunc() ColorerFunc {
return func(ns string, h Header, re RowEvent) tcell.Color {
if !Happy(ns, h, re.Row) {
return ErrColor
}
return tcell.ColorPaleGreen
}
return DefaultColorer
}

// Header returns a header row.
Expand Down
5 changes: 1 addition & 4 deletions internal/render/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

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

// ColorerFunc colors a resource row.
func (Dir) ColorerFunc() ColorerFunc {
return func(ns string, _ Header, re RowEvent) tcell.Color {
return tcell.ColorCadetBlue
}
return DefaultColorer
}

// Header returns a header row.
Expand Down
9 changes: 1 addition & 8 deletions internal/render/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strconv"

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

// ColorerFunc colors a resource row.
func (Helm) ColorerFunc() ColorerFunc {
return func(ns string, h Header, re RowEvent) tcell.Color {
if !Happy(ns, h, re.Row) {
return ErrColor
}

return tcell.ColorMediumSpringGreen
}
return DefaultColorer
}

// Header returns a header row.
Expand Down
5 changes: 1 addition & 4 deletions internal/render/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

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

// ColorerFunc colors a resource row.
func (Policy) ColorerFunc() ColorerFunc {
return func(ns string, _ Header, re RowEvent) tcell.Color {
return tcell.ColorMediumSpringGreen
}
return DefaultColorer
}

// Header returns a header row.
Expand Down
5 changes: 1 addition & 4 deletions internal/render/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"

"github.com/derailed/k9s/internal/client"
"github.com/derailed/tcell/v2"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
Expand Down Expand Up @@ -35,9 +34,7 @@ type PortForward struct {

// ColorerFunc colors a resource row.
func (PortForward) ColorerFunc() ColorerFunc {
return func(ns string, _ Header, re RowEvent) tcell.Color {
return tcell.ColorSkyblue
}
return DefaultColorer
}

// Header returns a header row.
Expand Down
5 changes: 1 addition & 4 deletions internal/render/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

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

// ColorerFunc colors a resource row.
func (Reference) ColorerFunc() ColorerFunc {
return func(ns string, _ Header, re RowEvent) tcell.Color {
return tcell.ColorCadetBlue
}
return DefaultColorer
}

// Header returns a header row.
Expand Down
5 changes: 1 addition & 4 deletions internal/render/screen_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path/filepath"
"time"

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

// ColorerFunc colors a resource row.
func (ScreenDump) ColorerFunc() ColorerFunc {
return func(ns string, _ Header, re RowEvent) tcell.Color {
return tcell.ColorNavajoWhite
}
return DefaultColorer
}

// Header returns a header row.
Expand Down
5 changes: 1 addition & 4 deletions internal/render/subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package render
import (
"fmt"

"github.com/derailed/tcell/v2"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
Expand All @@ -15,9 +14,7 @@ type Subject struct {

// ColorerFunc colors a resource row.
func (Subject) ColorerFunc() ColorerFunc {
return func(ns string, _ Header, re RowEvent) tcell.Color {
return tcell.ColorMediumSpringGreen
}
return DefaultColorer
}

// Header returns a header row.
Expand Down
5 changes: 2 additions & 3 deletions internal/ui/dialog/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/derailed/k9s/internal/config"
"github.com/derailed/k9s/internal/ui"
"github.com/derailed/tcell/v2"
"github.com/derailed/tview"
)

Expand All @@ -18,7 +17,7 @@ func ShowError(styles config.Dialog, pages *ui.Pages, msg string) {
SetButtonBackgroundColor(styles.ButtonBgColor.Color()).
SetButtonTextColor(styles.ButtonFgColor.Color()).
SetLabelColor(styles.LabelFgColor.Color()).
SetFieldTextColor(tcell.ColorIndianRed)
SetFieldTextColor(styles.FieldFgColor.Color())
f.AddButton("Dismiss", func() {
dismiss(pages)
})
Expand All @@ -29,7 +28,7 @@ func ShowError(styles config.Dialog, pages *ui.Pages, msg string) {
f.SetFocus(0)
modal := tview.NewModalForm("<error>", f)
modal.SetText(cowTalk(msg))
modal.SetTextColor(tcell.ColorOrangeRed)
modal.SetTextColor(styles.ErrorColor.Color())
modal.SetDoneFunc(func(int, string) {
dismiss(pages)
})
Expand Down
14 changes: 8 additions & 6 deletions internal/ui/flash.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewFlash(app *App) *Flash {
app: app,
TextView: tview.NewTextView(),
}
f.SetTextColor(tcell.ColorAqua)

f.SetDynamicColors(true)
f.SetTextAlign(tview.AlignCenter)
f.SetBorderPadding(0, 0, 1, 1)
Expand Down Expand Up @@ -70,7 +70,7 @@ func (f *Flash) SetMessage(m model.LevelMessage) {
f.Clear()
return
}
f.SetTextColor(flashColor(m.Level))
f.SetTextColor(f.flashColor(m.Level))
f.SetText(f.flashEmoji(m.Level) + " " + m.Text)
}

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

// Helpers...

func flashColor(l model.FlashLevel) tcell.Color {
func (f *Flash) flashColor(l model.FlashLevel) tcell.Color {
styles := f.app.Styles

// nolint:exhaustive
switch l {
case model.FlashWarn:
return tcell.ColorOrange
return styles.FlashColorWarn()
case model.FlashErr:
return tcell.ColorOrangeRed
return styles.FlashColorError()
default:
return tcell.ColorNavajoWhite
return styles.FlashColorOk()
}
}
3 changes: 1 addition & 2 deletions internal/ui/indicator.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/derailed/k9s/internal/config"
"github.com/derailed/k9s/internal/model"
"github.com/derailed/k9s/internal/render"
"github.com/derailed/tcell/v2"
"github.com/derailed/tview"
)

Expand All @@ -30,7 +29,7 @@ func NewStatusIndicator(app *App, styles *config.Styles) *StatusIndicator {
styles: styles,
}
s.SetTextAlign(tview.AlignCenter)
s.SetTextColor(tcell.ColorWhite)
s.SetTextColor(styles.FgColor())
s.SetBackgroundColor(styles.BgColor())
s.SetDynamicColors(true)
styles.AddListener(&s)
Expand Down
1 change: 0 additions & 1 deletion internal/ui/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func (t *Table) Init(ctx context.Context) {
t.SetBorderPadding(0, 0, 1, 1)
t.SetSelectable(true, false)
t.SetSelectionChangedFunc(t.selectionChanged)
t.SetBackgroundColor(tcell.ColorDefault)
t.Select(1, 0)
if cfg, ok := ctx.Value(internal.KeyViewConfig).(*config.CustomView); ok && cfg != nil {
cfg.AddListener(t.GVR().String(), t)
Expand Down
1 change: 0 additions & 1 deletion internal/ui/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (t *Tree) Init(ctx context.Context) error {
t.SetBorderAttributes(tcell.AttrBold)
t.SetBorderPadding(0, 0, 1, 1)
t.SetGraphics(true)
t.SetGraphicsColor(tcell.ColorCadetBlue)
t.SetInputCapture(t.keyboard)

return nil
Expand Down
2 changes: 0 additions & 2 deletions internal/view/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ func NewAlias(gvr client.GVR) ResourceViewer {
a := Alias{
ResourceViewer: NewBrowser(gvr),
}
a.GetTable().SetBorderFocusColor(tcell.ColorAliceBlue)
a.GetTable().SetSelectedStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite).Background(tcell.ColorAliceBlue).Attributes(tcell.AttrNone))
a.AddBindKeysFn(a.bindKeys)
a.SetContextFn(a.aliasContext)

Expand Down
3 changes: 0 additions & 3 deletions internal/view/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/derailed/k9s/internal/config"
"github.com/derailed/k9s/internal/perf"
"github.com/derailed/k9s/internal/ui"
"github.com/derailed/tcell/v2"
)

// Benchmark represents a service benchmark results view.
Expand All @@ -24,8 +23,6 @@ func NewBenchmark(gvr client.GVR) ResourceViewer {
b := Benchmark{
ResourceViewer: NewBrowser(gvr),
}
b.GetTable().SetBorderFocusColor(tcell.ColorSeaGreen)
b.GetTable().SetSelectedStyle(tcell.StyleDefault.Foreground(tcell.ColorWhite).Background(tcell.ColorSeaGreen).Attributes(tcell.AttrNone))
b.GetTable().SetSortCol(ageCol, true)
b.SetContextFn(b.benchContext)
b.GetTable().SetEnterFn(b.viewBench)
Expand Down
Loading