From 1415fedd6a204055e74c0c585bf2094c1fb39885 Mon Sep 17 00:00:00 2001 From: derailed Date: Thu, 20 Jun 2019 09:32:39 -0600 Subject: [PATCH] reworked skins --- README.md | 90 ++++---- internal/config/style.go | 192 ++++++++++++------ internal/config/style_test.go | 12 +- internal/config/test_assets/black_and_wtf.yml | 56 ++--- internal/views/app.go | 1 - internal/views/cluster_info.go | 4 +- internal/views/cmd.go | 2 +- internal/views/config.go | 12 +- internal/views/crumbs.go | 8 +- internal/views/details.go | 6 +- internal/views/log.go | 6 +- internal/views/log_test.go | 2 +- internal/views/logo.go | 4 +- internal/views/logs.go | 4 +- internal/views/master_detail.go | 16 -- internal/views/menu.go | 12 +- internal/views/pod.go | 2 +- internal/views/rbac.go | 2 +- internal/views/resource.go | 21 +- internal/views/secret.go | 2 +- internal/views/splash.go | 6 +- internal/views/status.go | 11 +- internal/views/status_test.go | 2 +- internal/views/table.go | 22 +- internal/views/table_helper.go | 8 +- internal/views/yaml.go | 14 +- internal/views/yaml_test.go | 2 +- skins/black_and_wtf.yml | 71 +++---- skins/in_the_navy.yml | 75 +++---- skins/stock.yml | 71 +++---- 30 files changed, 403 insertions(+), 333 deletions(-) diff --git a/README.md b/README.md index 57797a3c..911a532d 100644 --- a/README.md +++ b/README.md @@ -324,29 +324,46 @@ Below is a sample skin file, more skins would be available in the skins director # InTheNavy Skin... k9s: # General K9s styles - fgColor: dodgerblue - bgColor: white - logoColor: blue + body: + fgColor: dodgerblue + bgColor: white + logoColor: blue # ClusterInfoView styles. info: fgColor: lightskyblue sectionColor: steelblue - # Borders styles. - border: - fgColor: dodgerblue - focusColor: aliceblue - # MenuView attributes and styles. - menu: - fgColor: darkblue - keyColor: cornflowerblue - # Used for favorite namespaces - numKeyColor: cadetblue - # CrumbView attributes for history navigation. - crumb: - fgColor: white - bgColor: steelblue - # Active view settings - activeColor: skyblue + frame: + # Borders styles. + border: + fgColor: dodgerblue + focusColor: aliceblue + # MenuView attributes and styles. + menu: + fgColor: darkblue + keyColor: cornflowerblue + # Used for favorite namespaces + numKeyColor: cadetblue + # CrumbView attributes for history navigation. + crumbs: + fgColor: white + bgColor: steelblue + activeColor: skyblue + # Resource status and update styles + status: + newColor: blue + modifyColor: powderblue + addColor: lightskyblue + errorColor: indianred + highlightcolor: royalblue + killColor: slategray + completedColor: gray + # Border title styles. + title: + fgColor: aqua + bgColor: white + highlightColor: skyblue + counterColor: slateblue + filterColor: slategray # TableView attributes. table: fgColor: blue @@ -357,31 +374,16 @@ k9s: fgColor: white bgColor: darkblue sorterColor: orange - # Resource status and update styles - status: - newColor: blue - modifyColor: powderblue - addColor: lightskyblue - errorColor: indianred - highlightcolor: royalblue - killColor: slategray - completedColor: gray - # Border title styles. - title: - fgColor: aqua - bgColor: white - highlightColor: skyblue - counterColor: slateblue - filterColor: slategray - # YAML info styles. - yaml: - keyColor: steelblue - colonColor: blue - valueColor: royalblue - # Logs styles. - logs: - fgColor: white - bgColor: black + views: + # YAML info styles. + yaml: + keyColor: steelblue + colonColor: blue + valueColor: royalblue + # Logs styles. + logs: + fgColor: white + bgColor: black ``` Available color names are defined below: diff --git a/internal/config/style.go b/internal/config/style.go index 52bb7976..6b42fc84 100644 --- a/internal/config/style.go +++ b/internal/config/style.go @@ -17,23 +17,29 @@ var ( type ( // Styles tracks K9s styling options. Styles struct { - Style *Style `yaml:"k9s"` + K9s Style `yaml:"k9s"` } - // Style tracks K9s styles. - Style struct { - FgColor string `yaml:"fgColor"` - BgColor string `yaml:"bgColor"` - LogoColor string `yaml:"logoColor"` - Title *Title `yaml:"title"` - Border *Border `yaml:"border"` - Info *Info `yaml:"info"` - Menu *Menu `yaml:"menu"` - Crumb *Crumb `yaml:"crumb"` - Table *Table `yaml:"table"` - Status *Status `yaml:"status"` - Yaml *Yaml `yaml:"yaml"` - Log *Log `yaml:"logs"` + // Body tracks body styles. + Body struct { + FgColor string `yaml:"fgColor"` + BgColor string `yaml:"bgColor"` + LogoColor string `yaml:"logoColor"` + } + + // Frame tracks frame styles. + Frame struct { + Title Title `yaml:"title"` + Border Border `yaml:"border"` + Menu Menu `yaml:"menu"` + Crumb Crumb `yaml:"crumbs"` + Status Status `yaml:"status"` + } + + // Views tracks individual view styles. + Views struct { + Yaml Yaml `yaml:"yaml"` + Log Log `yaml:"logs"` } // Status tracks resource status styles. @@ -90,10 +96,10 @@ type ( // Table tracks table styles. Table struct { - FgColor string `yaml:"fgColor"` - BgColor string `yaml:"bgColor"` - CursorColor string `yaml:"cursorColor"` - Header *TableHeader `yaml:"header"` + FgColor string `yaml:"fgColor"` + BgColor string `yaml:"bgColor"` + CursorColor string `yaml:"cursorColor"` + Header TableHeader `yaml:"header"` } // TableHeader tracks table header styles. @@ -109,27 +115,54 @@ type ( KeyColor string `yaml:"keyColor"` NumKeyColor string `yaml:"numKeyColor"` } + + // Style tracks K9s styles. + Style struct { + Body Body `yaml:"body"` + Frame Frame `yaml:"frame"` + Info Info `yaml:"info"` + Table Table `yaml:"table"` + Views Views `yaml:"views"` + } ) -func newStyle() *Style { - return &Style{ - FgColor: "cadetblue", - BgColor: "black", - LogoColor: "orange", - Border: newBorder(), - Title: newTitle(), - Info: newInfo(), - Menu: newMenu(), - Crumb: newCrumb(), - Table: newTable(), - Status: newStatus(), - Yaml: newYaml(), - Log: newLog(), +func newStyle() Style { + return Style{ + Body: newBody(), + Frame: newFrame(), + Info: newInfo(), + Table: newTable(), + Views: newViews(), } } -func newStatus() *Status { - return &Status{ +func newViews() Views { + return Views{ + Yaml: newYaml(), + Log: newLog(), + } +} + +func newFrame() Frame { + return Frame{ + Title: newTitle(), + Border: newBorder(), + Menu: newMenu(), + Crumb: newCrumb(), + Status: newStatus(), + } +} + +func newBody() Body { + return Body{ + FgColor: "cadetblue", + BgColor: "black", + LogoColor: "orange", + } +} + +func newStatus() Status { + return Status{ NewColor: "lightskyblue", ModifyColor: "greenyellow", AddColor: "dodgerblue", @@ -141,16 +174,16 @@ func newStatus() *Status { } // NewLog returns a new log style. -func newLog() *Log { - return &Log{ +func newLog() Log { + return Log{ FgColor: "lightskyblue", BgColor: "black", } } // NewYaml returns a new yaml style. -func newYaml() *Yaml { - return &Yaml{ +func newYaml() Yaml { + return Yaml{ KeyColor: "steelblue", ColonColor: "white", ValueColor: "papayawhip", @@ -158,8 +191,8 @@ func newYaml() *Yaml { } // NewTitle returns a new title style. -func newTitle() *Title { - return &Title{ +func newTitle() Title { + return Title{ FgColor: "aqua", BgColor: "black", HighlightColor: "fuchsia", @@ -169,16 +202,16 @@ func newTitle() *Title { } // NewInfo returns a new info style. -func newInfo() *Info { - return &Info{ +func newInfo() Info { + return Info{ SectionColor: "white", FgColor: "orange", } } // NewTable returns a new table style. -func newTable() *Table { - return &Table{ +func newTable() Table { + return Table{ FgColor: "aqua", BgColor: "black", CursorColor: "aqua", @@ -187,8 +220,8 @@ func newTable() *Table { } // NewTableHeader returns a new table header style. -func newTableHeader() *TableHeader { - return &TableHeader{ +func newTableHeader() TableHeader { + return TableHeader{ FgColor: "white", BgColor: "black", SorterColor: "aqua", @@ -196,8 +229,8 @@ func newTableHeader() *TableHeader { } // NewCrumb returns a new crumbs style. -func newCrumb() *Crumb { - return &Crumb{ +func newCrumb() Crumb { + return Crumb{ FgColor: "black", BgColor: "aqua", ActiveColor: "orange", @@ -205,16 +238,16 @@ func newCrumb() *Crumb { } // NewBorder returns a new border style. -func newBorder() *Border { - return &Border{ +func newBorder() Border { + return Border{ FgColor: "dodgerblue", FocusColor: "lightskyblue", } } // NewMenu returns a new menu style. -func newMenu() *Menu { - return &Menu{ +func newMenu() Menu { + return Menu{ FgColor: "white", KeyColor: "dodgerblue", NumKeyColor: "fuchsia", @@ -223,18 +256,48 @@ func newMenu() *Menu { // NewStyles creates a new default config. func NewStyles(path string) (*Styles, error) { - s := &Styles{Style: newStyle()} + s := &Styles{K9s: newStyle()} return s, s.load(path) } // FgColor returns the foreground color. func (s *Styles) FgColor() tcell.Color { - return AsColor(s.Style.FgColor) + return AsColor(s.Body().FgColor) } // BgColor returns the background color. func (s *Styles) BgColor() tcell.Color { - return AsColor(s.Style.BgColor) + return AsColor(s.Body().BgColor) +} + +// Body returns body styles. +func (s *Styles) Body() Body { + return s.K9s.Body +} + +// Frame returns frame styles. +func (s *Styles) Frame() Frame { + return s.K9s.Frame +} + +// Crumb returns crumb styles. +func (s *Styles) Crumb() Crumb { + return s.Frame().Crumb +} + +// Title returns title styles. +func (s *Styles) Title() Title { + return s.Frame().Title +} + +// Table returns table styles. +func (s *Styles) Table() Table { + return s.K9s.Table +} + +// Views returns views styles. +func (s *Styles) Views() Views { + return s.K9s.Views } // Load K9s configuration from file @@ -244,25 +307,20 @@ func (s *Styles) load(path string) error { return err } - var cfg Styles - if err := yaml.Unmarshal(f, &cfg); err != nil { + if err := yaml.Unmarshal(f, s); err != nil { return err } - if cfg.Style != nil { - s.Style = cfg.Style - } - return nil } // Update apply terminal colors based on styles. func (s *Styles) Update() { - tview.Styles.PrimitiveBackgroundColor = AsColor(s.Style.BgColor) - tview.Styles.ContrastBackgroundColor = AsColor(s.Style.BgColor) - tview.Styles.PrimaryTextColor = AsColor(s.Style.FgColor) - tview.Styles.BorderColor = AsColor(s.Style.Border.FgColor) - tview.Styles.FocusColor = AsColor(s.Style.Border.FocusColor) + tview.Styles.PrimitiveBackgroundColor = s.BgColor() + tview.Styles.ContrastBackgroundColor = s.BgColor() + tview.Styles.PrimaryTextColor = s.FgColor() + tview.Styles.BorderColor = AsColor(s.K9s.Frame.Border.FgColor) + tview.Styles.FocusColor = AsColor(s.K9s.Frame.Border.FocusColor) } // AsColor checks color index, if match return color otherwise pink it is. diff --git a/internal/config/style_test.go b/internal/config/style_test.go index 396ec86b..45fb2a56 100644 --- a/internal/config/style_test.go +++ b/internal/config/style_test.go @@ -14,9 +14,9 @@ func TestSkinNone(t *testing.T) { s.Update() - assert.Equal(t, "cadetblue", s.Style.FgColor) - assert.Equal(t, "black", s.Style.BgColor) - assert.Equal(t, "black", s.Style.Table.BgColor) + assert.Equal(t, "cadetblue", s.Body().FgColor) + assert.Equal(t, "black", s.Body().BgColor) + assert.Equal(t, "black", s.Table().BgColor) assert.Equal(t, tcell.ColorCadetBlue, s.FgColor()) assert.Equal(t, tcell.ColorBlack, s.BgColor()) assert.Equal(t, tcell.ColorBlack, tview.Styles.PrimitiveBackgroundColor) @@ -30,9 +30,9 @@ func TestSkin(t *testing.T) { s.Update() - assert.Equal(t, "white", s.Style.FgColor) - assert.Equal(t, "black", s.Style.BgColor) - assert.Equal(t, "black", s.Style.Table.BgColor) + assert.Equal(t, "white", s.Body().FgColor) + assert.Equal(t, "black", s.Body().BgColor) + assert.Equal(t, "black", s.Table().BgColor) assert.Equal(t, tcell.ColorWhite, s.FgColor()) assert.Equal(t, tcell.ColorBlack, s.BgColor()) assert.Equal(t, tcell.ColorBlack, tview.Styles.PrimitiveBackgroundColor) diff --git a/internal/config/test_assets/black_and_wtf.yml b/internal/config/test_assets/black_and_wtf.yml index 7046c40a..5cef5c95 100644 --- a/internal/config/test_assets/black_and_wtf.yml +++ b/internal/config/test_assets/black_and_wtf.yml @@ -1,21 +1,36 @@ k9s: - fgColor: white - bgColor: black - logoColor: white + body: + fgColor: white + bgColor: black + logoColor: white info: fgColor: navajowhite sectionColor: white - border: - fgColor: white - focusColor: white - menu: - fgColor: white - keyColor: white - numKeyColor: navajowhite - crumb: - fgColor: black - bgColor: navajowhite - activeColor: whitesmoke + frame: + border: + fgColor: white + focusColor: white + menu: + fgColor: white + keyColor: white + numKeyColor: navajowhite + crumb: + fgColor: black + bgColor: navajowhite + activeColor: whitesmoke + status: + newColor: ghostwhite + modifyColor: navajowhite + addColor: darkslategray + errorColor: whitesmoke + highlightcolor: dimgray + killColor: slategray + completedColor: gray + title: + fgColor: ghostwhite + highlightColor: navajowhite + counterColor: navajowhite + filterColor: slategray table: fgColor: white bgColor: black @@ -24,16 +39,3 @@ k9s: fgColor: darkgray bgColor: black sorterColor: white - status: - newColor: ghostwhite - modifyColor: navajowhite - addColor: darkslategray - errorColor: whitesmoke - highlightcolor: dimgray - killColor: slategray - completedColor: gray - title: - fgColor: ghostwhite - highlightColor: navajowhite - counterColor: navajowhite - filterColor: slategray diff --git a/internal/views/app.go b/internal/views/app.go index 2935c179..a6aac0bd 100644 --- a/internal/views/app.go +++ b/internal/views/app.go @@ -194,7 +194,6 @@ func (a *appView) Run() { // Only enable skin updater while in dev mode. if a.hasSkins { - var ctx context.Context if err := a.stylesUpdater(ctx, a); err != nil { log.Error().Err(err).Msg("Unable to track skin changes") } diff --git a/internal/views/cluster_info.go b/internal/views/cluster_info.go index 43440fc0..593c2746 100644 --- a/internal/views/cluster_info.go +++ b/internal/views/cluster_info.go @@ -76,7 +76,7 @@ func (v *clusterInfoView) sectionCell(t string) *tview.TableCell { c := tview.NewTableCell(t + ":") c.SetAlign(tview.AlignLeft) var s tcell.Style - c.SetStyle(s.Bold(true).Foreground(config.AsColor(v.app.styles.Style.Info.SectionColor))) + c.SetStyle(s.Bold(true).Foreground(config.AsColor(v.app.styles.K9s.Info.SectionColor))) c.SetBackgroundColor(v.app.styles.BgColor()) return c @@ -85,7 +85,7 @@ func (v *clusterInfoView) sectionCell(t string) *tview.TableCell { func (v *clusterInfoView) infoCell(t string) *tview.TableCell { c := tview.NewTableCell(t) c.SetExpansion(2) - c.SetTextColor(config.AsColor(v.app.styles.Style.Info.FgColor)) + c.SetTextColor(config.AsColor(v.app.styles.K9s.Info.FgColor)) c.SetBackgroundColor(v.app.styles.BgColor()) return c diff --git a/internal/views/cmd.go b/internal/views/cmd.go index f3fc6705..d20011a4 100644 --- a/internal/views/cmd.go +++ b/internal/views/cmd.go @@ -27,7 +27,7 @@ func newCmdView(styles *config.Styles, ic rune) *cmdView { v.SetBorder(true) v.SetBorderPadding(0, 0, 1, 1) v.SetBackgroundColor(styles.BgColor()) - v.SetBorderColor(config.AsColor(styles.Style.Border.FocusColor)) + v.SetBorderColor(config.AsColor(styles.Frame().Border.FocusColor)) v.SetTextColor(styles.FgColor()) } return &v diff --git a/internal/views/config.go b/internal/views/config.go index 1ae047d0..41df8515 100644 --- a/internal/views/config.go +++ b/internal/views/config.go @@ -65,10 +65,10 @@ func (c *configurator) refreshStyles() { } c.styles.Update() - stdColor = config.AsColor(c.styles.Style.Status.NewColor) - addColor = config.AsColor(c.styles.Style.Status.AddColor) - modColor = config.AsColor(c.styles.Style.Status.ModifyColor) - errColor = config.AsColor(c.styles.Style.Status.ErrorColor) - highlightColor = config.AsColor(c.styles.Style.Status.HighlightColor) - completedColor = config.AsColor(c.styles.Style.Status.CompletedColor) + stdColor = config.AsColor(c.styles.Frame().Status.NewColor) + addColor = config.AsColor(c.styles.Frame().Status.AddColor) + modColor = config.AsColor(c.styles.Frame().Status.ModifyColor) + errColor = config.AsColor(c.styles.Frame().Status.ErrorColor) + highlightColor = config.AsColor(c.styles.Frame().Status.HighlightColor) + completedColor = config.AsColor(c.styles.Frame().Status.CompletedColor) } diff --git a/internal/views/crumbs.go b/internal/views/crumbs.go index 24816818..09420ef7 100644 --- a/internal/views/crumbs.go +++ b/internal/views/crumbs.go @@ -27,14 +27,14 @@ func newCrumbsView(styles *config.Styles) *crumbsView { func (v *crumbsView) update(crumbs []string) { v.Clear() - last, bgColor := len(crumbs)-1, v.styles.Style.Crumb.BgColor + last, bgColor := len(crumbs)-1, v.styles.Frame().Crumb.BgColor for i, c := range crumbs { if i == last { - bgColor = v.styles.Style.Crumb.ActiveColor + bgColor = v.styles.Frame().Crumb.ActiveColor } fmt.Fprintf(v, "[%s:%s:b] <%s> [-:%s:-] ", - v.styles.Style.Crumb.FgColor, + v.styles.Frame().Crumb.FgColor, bgColor, c, - v.styles.Style.BgColor) + v.styles.Body().BgColor) } } diff --git a/internal/views/details.go b/internal/views/details.go index 36ef2716..c2c53f9a 100644 --- a/internal/views/details.go +++ b/internal/views/details.go @@ -36,7 +36,7 @@ func newDetailsView(app *appView, backFn actionHandler) *detailsView { v.SetDynamicColors(true) v.SetRegions(true) v.SetBorder(true) - v.SetBorderFocusColor(config.AsColor(v.app.styles.Style.Border.FocusColor)) + v.SetBorderFocusColor(config.AsColor(v.app.styles.Frame().Border.FocusColor)) v.SetHighlightColor(tcell.ColorOrange) v.SetTitleColor(tcell.ColorAqua) v.SetInputCapture(v.keyboard) @@ -196,9 +196,9 @@ func (v *detailsView) refreshTitle() { func (v *detailsView) setTitle(t string) { v.title = t - title := skinTitle(fmt.Sprintf(detailsTitleFmt, v.category, t), v.app.styles.Style) + title := skinTitle(fmt.Sprintf(detailsTitleFmt, v.category, t), v.app.styles.Frame()) if !v.cmdBuff.empty() { - title += skinTitle(fmt.Sprintf(searchFmt, v.cmdBuff.String()), v.app.styles.Style) + title += skinTitle(fmt.Sprintf(searchFmt, v.cmdBuff.String()), v.app.styles.Frame()) } v.SetTitle(title) } diff --git a/internal/views/log.go b/internal/views/log.go index b52186c7..eabc1d87 100644 --- a/internal/views/log.go +++ b/internal/views/log.go @@ -33,15 +33,15 @@ func newLogView(title string, app *appView, backFn actionHandler) *logView { v.autoScroll = 1 v.backFn = backFn v.SetBorder(true) - v.SetBackgroundColor(config.AsColor(app.styles.Style.Log.BgColor)) + v.SetBackgroundColor(config.AsColor(app.styles.Views().Log.BgColor)) v.SetBorderPadding(0, 0, 1, 1) v.logs = newDetailsView(app, backFn) { v.logs.SetBorder(false) v.logs.setCategory("Logs") v.logs.SetDynamicColors(true) - v.logs.SetTextColor(config.AsColor(app.styles.Style.Log.FgColor)) - v.logs.SetBackgroundColor(config.AsColor(app.styles.Style.Log.BgColor)) + v.logs.SetTextColor(config.AsColor(app.styles.Views().Log.FgColor)) + v.logs.SetBackgroundColor(config.AsColor(app.styles.Views().Log.BgColor)) v.logs.SetWrap(true) v.logs.SetMaxBuffer(app.config.K9s.LogBufferSize) } diff --git a/internal/views/log_test.go b/internal/views/log_test.go index 2584d9ef..992b1d7a 100644 --- a/internal/views/log_test.go +++ b/internal/views/log_test.go @@ -32,7 +32,7 @@ func TestLogViewFlush(t *testing.T) { v.toggleScrollCmd(nil) assert.Equal(t, "blee\nbozo\n", v.logs.GetText(true)) - assert.Equal(t, " Autoscroll: Off ", v.status.GetText(true)) + assert.Equal(t, " Autoscroll: Off ", v.status.GetText(true)) v.toggleScrollCmd(nil) assert.Equal(t, " Autoscroll: On ", v.status.GetText(true)) } diff --git a/internal/views/logo.go b/internal/views/logo.go index f037bdcb..999b8f0e 100644 --- a/internal/views/logo.go +++ b/internal/views/logo.go @@ -23,7 +23,7 @@ func newLogoView(styles *config.Styles) *logoView { v.SetDirection(tview.FlexRow) v.AddItem(v.logo, 0, 6, false) v.AddItem(v.status, 0, 1, false) - v.refreshLogo(styles.Style.LogoColor) + v.refreshLogo(styles.Body().LogoColor) return &v } @@ -31,7 +31,7 @@ func newLogoView(styles *config.Styles) *logoView { func (v *logoView) reset() { v.status.Clear() v.status.SetBackgroundColor(v.styles.BgColor()) - v.refreshLogo(v.styles.Style.LogoColor) + v.refreshLogo(v.styles.Body().LogoColor) } func (v *logoView) err(msg string) { diff --git a/internal/views/logs.go b/internal/views/logs.go index 7f3e8b5c..9e7513c3 100644 --- a/internal/views/logs.go +++ b/internal/views/logs.go @@ -111,9 +111,9 @@ func (v *logsView) doLoad(path, co string) error { var fmat string if co == "" { - fmat = skinTitle(fmt.Sprintf(logFmt, path), v.app.styles.Style) + fmat = skinTitle(fmt.Sprintf(logFmt, path), v.app.styles.Frame()) } else { - fmat = skinTitle(fmt.Sprintf(logCoFmt, path, co), v.app.styles.Style) + fmat = skinTitle(fmt.Sprintf(logCoFmt, path, co), v.app.styles.Frame()) } l.SetTitle(fmat) diff --git a/internal/views/master_detail.go b/internal/views/master_detail.go index 501233e9..e4e9de96 100644 --- a/internal/views/master_detail.go +++ b/internal/views/master_detail.go @@ -18,8 +18,6 @@ type masterDetail struct { selectedRow int selectedFn func() string enterFn enterFn - colorerFn colorerFn - decorateFn decorateFn extraActionsFn func(keyActions) } @@ -45,11 +43,6 @@ func (v *masterDetail) init(ns string, backCmd actionHandler) { if v.currentNS != resource.NotNamespaced { v.currentNS = ns } - colorer := defaultColorer - if v.colorerFn != nil { - colorer = v.colorerFn - } - v.masterPage().setColorer(colorer) } func (v *masterDetail) setExtraActionsFn(f actionsFn) { @@ -79,19 +72,10 @@ func (v *masterDetail) hints() hints { return v.CurrentPage().Item.(hinter).hints() } -func (v *masterDetail) setColorerFn(f colorerFn) { - v.colorerFn = f - v.masterPage().setColorer(f) -} - func (v *masterDetail) setEnterFn(f enterFn) { v.enterFn = f } -func (v *masterDetail) setDecorateFn(f decorateFn) { - v.decorateFn = f -} - func (v *masterDetail) masterPage() *tableView { return v.GetPrimitive("master").(*tableView) } diff --git a/internal/views/menu.go b/internal/views/menu.go index d2add2ed..78e64000 100644 --- a/internal/views/menu.go +++ b/internal/views/menu.go @@ -178,16 +178,16 @@ func (*menuView) toMnemonic(s string) string { func (v *menuView) formatMenu(h hint, size int) string { i, err := strconv.Atoi(h.mnemonic) if err == nil { - fmat := strings.Replace(menuIndexFmt, "[key", "["+v.styles.Style.Menu.NumKeyColor, 1) - fmat = strings.Replace(fmat, ":bg:", ":"+v.styles.Style.Title.BgColor+":", -1) - fmat = strings.Replace(fmat, "[fg", "["+v.styles.Style.Menu.FgColor, 1) + fmat := strings.Replace(menuIndexFmt, "[key", "["+v.styles.Frame().Menu.NumKeyColor, 1) + fmat = strings.Replace(fmat, ":bg:", ":"+v.styles.Frame().Title.BgColor+":", -1) + fmat = strings.Replace(fmat, "[fg", "["+v.styles.Frame().Menu.FgColor, 1) return fmt.Sprintf(fmat, i, resource.Truncate(h.description, 14)) } menuFmt := " [key:bg:b]%-" + strconv.Itoa(size+2) + "s [fg:bg:d]%s " - fmat := strings.Replace(menuFmt, "[key", "["+v.styles.Style.Menu.KeyColor, 1) - fmat = strings.Replace(fmat, "[fg", "["+v.styles.Style.Menu.FgColor, 1) - fmat = strings.Replace(fmat, ":bg:", ":"+v.styles.Style.Title.BgColor+":", -1) + fmat := strings.Replace(menuFmt, "[key", "["+v.styles.Frame().Menu.KeyColor, 1) + fmat = strings.Replace(fmat, "[fg", "["+v.styles.Frame().Menu.FgColor, 1) + fmat = strings.Replace(fmat, ":bg:", ":"+v.styles.Frame().Title.BgColor+":", -1) return fmt.Sprintf(fmat, v.toMnemonic(h.mnemonic), h.description) } diff --git a/internal/views/pod.go b/internal/views/pod.go index d0ef6f3b..f4c0a630 100644 --- a/internal/views/pod.go +++ b/internal/views/pod.go @@ -79,7 +79,7 @@ func (v *podView) listContainers(app *appView, _, res, sel string) { pod := po.(*v1.Pod) mx := k8s.NewMetricsServer(app.conn()) list := resource.NewContainerList(app.conn(), mx, pod) - title := skinTitle(fmt.Sprintf(containerFmt, "Containers", sel), app.styles.Style) + title := skinTitle(fmt.Sprintf(containerFmt, "Containers", sel), app.styles.Frame()) // Stop my updater if v.cancelFn != nil { diff --git a/internal/views/rbac.go b/internal/views/rbac.go index 77513496..b99161c3 100644 --- a/internal/views/rbac.go +++ b/internal/views/rbac.go @@ -124,7 +124,7 @@ func (v *rbacView) bindKeys() { } func (v *rbacView) getTitle() string { - return skinTitle(fmt.Sprintf(rbacTitleFmt, rbacTitle, v.roleName), v.app.styles.Style) + return skinTitle(fmt.Sprintf(rbacTitleFmt, rbacTitle, v.roleName), v.app.styles.Frame()) } func (v *rbacView) hints() hints { diff --git a/internal/views/resource.go b/internal/views/resource.go index cdc70bcc..0abebb28 100644 --- a/internal/views/resource.go +++ b/internal/views/resource.go @@ -27,6 +27,8 @@ type ( cancelFn context.CancelFunc parentCtx context.Context path *string + colorerFn colorerFn + decorateFn decorateFn } ) @@ -48,6 +50,12 @@ func (v *resourceView) init(ctx context.Context, ns string) { var vctx context.Context vctx, v.cancelFn = context.WithCancel(ctx) + colorer := defaultColorer + if v.colorerFn != nil { + colorer = v.colorerFn + } + v.masterPage().setColorer(colorer) + v.update(vctx) v.app.clusterInfoRefresh() v.refresh() @@ -59,6 +67,15 @@ func (v *resourceView) init(ctx context.Context, ns string) { } } +func (v *resourceView) setColorerFn(f colorerFn) { + v.colorerFn = f + v.masterPage().setColorer(f) +} + +func (v *resourceView) setDecorateFn(f decorateFn) { + v.decorateFn = f +} + func (v *resourceView) filterResource(sel string) { v.list.SetLabelSelector(sel) v.refresh() @@ -157,7 +174,7 @@ func (v *resourceView) defaultEnter(ns, resource, selection string) { details.setCategory("Describe") details.setTitle(selection) details.SetTextColor(v.app.styles.FgColor()) - details.SetText(colorizeYAML(v.app.styles.Style, yaml)) + details.SetText(colorizeYAML(v.app.styles.Views().Yaml, yaml)) details.ScrollToBeginning() v.switchPage("details") @@ -187,7 +204,7 @@ func (v *resourceView) viewCmd(evt *tcell.EventKey) *tcell.EventKey { details.setCategory("YAML") details.setTitle(sel) details.SetTextColor(v.app.styles.FgColor()) - details.SetText(colorizeYAML(v.app.styles.Style, raw)) + details.SetText(colorizeYAML(v.app.styles.Views().Yaml, raw)) details.ScrollToBeginning() v.switchPage("details") diff --git a/internal/views/secret.go b/internal/views/secret.go index 0058cd81..d720a33c 100644 --- a/internal/views/secret.go +++ b/internal/views/secret.go @@ -50,7 +50,7 @@ func (v *secretView) decodeCmd(evt *tcell.EventKey) *tcell.EventKey { details.setCategory("Decoder") details.setTitle(sel) details.SetTextColor(v.app.styles.FgColor()) - details.SetText(colorizeYAML(v.app.styles.Style, string(raw))) + details.SetText(colorizeYAML(v.app.styles.Views().Yaml, string(raw))) details.ScrollToBeginning() v.switchPage("details") diff --git a/internal/views/splash.go b/internal/views/splash.go index 5790f876..164daec8 100644 --- a/internal/views/splash.go +++ b/internal/views/splash.go @@ -63,13 +63,13 @@ func newSplash(styles *config.Styles, version string) *splashView { } func (v *splashView) layoutLogo(t *tview.TextView, styles *config.Styles) { - logo := strings.Join(Logo, fmt.Sprintf("\n[%s::b]", styles.Style.LogoColor)) + logo := strings.Join(Logo, fmt.Sprintf("\n[%s::b]", styles.Body().LogoColor)) fmt.Fprintf(t, "%s[%s::b]%s\n", strings.Repeat("\n", 2), - styles.Style.LogoColor, + styles.Body().LogoColor, logo) } func (v *splashView) layoutRev(t *tview.TextView, rev string, styles *config.Styles) { - fmt.Fprintf(t, "[%s::b]Revision [red::b]%s", styles.Style.FgColor, rev) + fmt.Fprintf(t, "[%s::b]Revision [red::b]%s", styles.Body().FgColor, rev) } diff --git a/internal/views/status.go b/internal/views/status.go index c0d876ba..9adbea5b 100644 --- a/internal/views/status.go +++ b/internal/views/status.go @@ -16,7 +16,7 @@ type statusView struct { func newStatusView(styles *config.Styles) *statusView { v := statusView{styles: styles, TextView: tview.NewTextView()} { - v.SetBackgroundColor(config.AsColor(styles.Style.Log.BgColor)) + v.SetBackgroundColor(config.AsColor(styles.Views().Log.BgColor)) v.SetTextAlign(tview.AlignRight) v.SetDynamicColors(true) } @@ -25,14 +25,11 @@ func newStatusView(styles *config.Styles) *statusView { func (v *statusView) update(status []string) { v.Clear() - last, bgColor := len(status)-1, v.styles.Style.Crumb.BgColor + last, bgColor := len(status)-1, v.styles.Frame().Crumb.BgColor for i, c := range status { if i == last { - bgColor = v.styles.Style.Crumb.ActiveColor + bgColor = v.styles.Frame().Crumb.ActiveColor } - fmt.Fprintf(v, "[%s:%s:b] %s [-:%s:-] ", - v.styles.Style.Crumb.FgColor, - bgColor, c, - v.styles.Style.BgColor) + fmt.Fprintf(v, "[%s:%s:b] %-15s ", v.styles.Frame().Crumb.FgColor, bgColor, c) } } diff --git a/internal/views/status_test.go b/internal/views/status_test.go index 4cd67d5c..acdd0485 100644 --- a/internal/views/status_test.go +++ b/internal/views/status_test.go @@ -12,5 +12,5 @@ func TestNewStatus(t *testing.T) { v := newStatusView(defaults) v.update([]string{"blee", "duh"}) - assert.Equal(t, "[black:aqua:b] blee [-:black:-] [black:orange:b] duh [-:black:-] \n", v.GetText(false)) + assert.Equal(t, "[black:aqua:b] blee [black:orange:b] duh \n", v.GetText(false)) } diff --git a/internal/views/table.go b/internal/views/table.go index 1f57ba54..0f13a336 100644 --- a/internal/views/table.go +++ b/internal/views/table.go @@ -75,9 +75,9 @@ func newTableView(app *appView, title string) *tableView { } v.SetFixed(1, 0) v.SetBorder(true) - v.SetBackgroundColor(config.AsColor(app.styles.Style.Table.BgColor)) - v.SetBorderColor(config.AsColor(app.styles.Style.Table.FgColor)) - v.SetBorderFocusColor(config.AsColor(app.styles.Style.Border.FocusColor)) + v.SetBackgroundColor(config.AsColor(app.styles.Table().BgColor)) + v.SetBorderColor(config.AsColor(app.styles.Table().FgColor)) + v.SetBorderFocusColor(config.AsColor(app.styles.Frame().Border.FocusColor)) v.SetBorderAttributes(tcell.AttrBold) v.SetBorderPadding(0, 0, 1, 1) v.cmdBuff.addListener(app.cmd()) @@ -85,7 +85,7 @@ func newTableView(app *appView, title string) *tableView { v.SetSelectable(true, false) v.SetSelectedStyle( tcell.ColorBlack, - config.AsColor(app.styles.Style.Table.CursorColor), + config.AsColor(app.styles.Table().CursorColor), tcell.AttrBold, ) v.SetInputCapture(v.keyboard) @@ -379,8 +379,8 @@ func (v *tableView) doUpdate(data resource.TableData) { pads := make(maxyPad, len(data.Header)) computeMaxColumns(pads, v.sortCol.index, data) var row int - fg := config.AsColor(v.app.styles.Style.Table.Header.FgColor) - bg := config.AsColor(v.app.styles.Style.Table.Header.BgColor) + fg := config.AsColor(v.app.styles.Table().Header.FgColor) + bg := config.AsColor(v.app.styles.Table().Header.BgColor) for col, h := range data.Header { v.addHeaderCell(data.NumCols[h], col, h) c := v.GetCell(0, col) @@ -394,7 +394,7 @@ func (v *tableView) doUpdate(data resource.TableData) { sortFn = v.sortFn } prim, sec := sortAllRows(v.sortCol, data.Rows, sortFn) - fgColor := config.AsColor(v.app.styles.Style.Table.FgColor) + fgColor := config.AsColor(v.app.styles.Table().FgColor) for _, pk := range prim { for _, sk := range sec[pk] { if v.colorerFn != nil { @@ -417,7 +417,7 @@ func (v *tableView) doUpdate(data resource.TableData) { } func (v *tableView) addHeaderCell(numerical bool, col int, name string) { - c := tview.NewTableCell(sortIndicator(v.sortCol, v.app.styles.Style, col, name)) + c := tview.NewTableCell(sortIndicator(v.sortCol, v.app.styles.Table(), col, name)) c.SetExpansion(1) if numerical || cpuRX.MatchString(name) || memRX.MatchString(name) { c.SetAlign(tview.AlignRight) @@ -454,13 +454,13 @@ func (v *tableView) resetTitle() { } switch v.currentNS { case resource.NotNamespaced, "*": - title = skinTitle(fmt.Sprintf(titleFmt, v.baseTitle, rc), v.app.styles.Style) + title = skinTitle(fmt.Sprintf(titleFmt, v.baseTitle, rc), v.app.styles.Frame()) default: ns := v.currentNS if ns == resource.AllNamespaces { ns = resource.AllNamespace } - title = skinTitle(fmt.Sprintf(nsTitleFmt, v.baseTitle, ns, rc), v.app.styles.Style) + title = skinTitle(fmt.Sprintf(nsTitleFmt, v.baseTitle, ns, rc), v.app.styles.Frame()) } if !v.cmdBuff.isActive() && !v.cmdBuff.empty() { @@ -468,7 +468,7 @@ func (v *tableView) resetTitle() { if isLabelSelector(cmd) { cmd = trimLabelSelector(cmd) } - title += skinTitle(fmt.Sprintf(searchFmt, cmd), v.app.styles.Style) + title += skinTitle(fmt.Sprintf(searchFmt, cmd), v.app.styles.Frame()) } v.SetTitle(title) } diff --git a/internal/views/table_helper.go b/internal/views/table_helper.go index 867e3b03..23486261 100644 --- a/internal/views/table_helper.go +++ b/internal/views/table_helper.go @@ -8,6 +8,7 @@ import ( "github.com/derailed/k9s/internal/config" "github.com/derailed/k9s/internal/resource" + "github.com/rs/zerolog/log" ) var labelCmd = regexp.MustCompile(`\A\-l`) @@ -28,7 +29,8 @@ func trimLabelSelector(s string) string { return strings.TrimSpace(s[2:]) } -func skinTitle(fmat string, style *config.Style) string { +func skinTitle(fmat string, style config.Frame) string { + log.Debug().Msgf("BG color %#v", style.Title.BgColor) fmat = strings.Replace(fmat, "[fg:bg", "["+style.Title.FgColor+":"+style.Title.BgColor, -1) fmat = strings.Replace(fmat, "[hilite", "["+style.Title.HighlightColor, 1) fmat = strings.Replace(fmat, "[key", "["+style.Menu.NumKeyColor, 1) @@ -76,7 +78,7 @@ func sortAllRows(col sortColumn, rows resource.RowEvents, sortFn sortFn) (resour return prim, sec } -func sortIndicator(col sortColumn, style *config.Style, index int, name string) string { +func sortIndicator(col sortColumn, style config.Table, index int, name string) string { if col.index != index { return name } @@ -85,5 +87,5 @@ func sortIndicator(col sortColumn, style *config.Style, index int, name string) if col.asc { order = ascIndicator } - return fmt.Sprintf("%s[%s::]%s[::]", name, style.Table.Header.SorterColor, order) + return fmt.Sprintf("%s[%s::]%s[::]", name, style.Header.SorterColor, order) } diff --git a/internal/views/yaml.go b/internal/views/yaml.go index f4bb5ab8..e197a6ef 100644 --- a/internal/views/yaml.go +++ b/internal/views/yaml.go @@ -19,17 +19,17 @@ const ( yamlValueFmt = "[val::]%s" ) -func colorizeYAML(style *config.Style, raw string) string { +func colorizeYAML(style config.Yaml, raw string) string { lines := strings.Split(raw, "\n") - fullFmt := strings.Replace(yamlFullFmt, "[key", "["+style.Yaml.KeyColor, 1) - fullFmt = strings.Replace(fullFmt, "[colon", "["+style.Yaml.ColonColor, 1) - fullFmt = strings.Replace(fullFmt, "[val", "["+style.Yaml.ValueColor, 1) + fullFmt := strings.Replace(yamlFullFmt, "[key", "["+style.KeyColor, 1) + fullFmt = strings.Replace(fullFmt, "[colon", "["+style.ColonColor, 1) + fullFmt = strings.Replace(fullFmt, "[val", "["+style.ValueColor, 1) - keyFmt := strings.Replace(yamlKeyFmt, "[key", "["+style.Yaml.KeyColor, 1) - keyFmt = strings.Replace(keyFmt, "[colon", "["+style.Yaml.ColonColor, 1) + keyFmt := strings.Replace(yamlKeyFmt, "[key", "["+style.KeyColor, 1) + keyFmt = strings.Replace(keyFmt, "[colon", "["+style.ColonColor, 1) - valFmt := strings.Replace(yamlValueFmt, "[val", "["+style.Yaml.ValueColor, 1) + valFmt := strings.Replace(yamlValueFmt, "[val", "["+style.ValueColor, 1) buff := make([]string, 0, len(lines)) for _, l := range lines { diff --git a/internal/views/yaml_test.go b/internal/views/yaml_test.go index 096211fb..7b89b24b 100644 --- a/internal/views/yaml_test.go +++ b/internal/views/yaml_test.go @@ -43,6 +43,6 @@ func TestYaml(t *testing.T) { s, _ := config.NewStyles("skins/stock.yml") for _, u := range uu { - assert.Equal(t, u.e, colorizeYAML(s.Style, u.s)) + assert.Equal(t, u.e, colorizeYAML(s.Views().Yaml, u.s)) } } diff --git a/skins/black_and_wtf.yml b/skins/black_and_wtf.yml index ee11a491..4fe8393b 100644 --- a/skins/black_and_wtf.yml +++ b/skins/black_and_wtf.yml @@ -1,21 +1,36 @@ k9s: - fgColor: white - bgColor: black - logoColor: white + body: + fgColor: white + bgColor: black + logoColor: white info: fgColor: navajowhite sectionColor: white - border: - fgColor: white - focusColor: white - menu: - fgColor: white - keyColor: white - numKeyColor: navajowhite - crumb: - fgColor: black - bgColor: navajowhite - activeColor: whitesmoke + frame: + border: + fgColor: white + focusColor: white + menu: + fgColor: white + keyColor: white + numKeyColor: navajowhite + crumbs: + fgColor: black + bgColor: navajowhite + activeColor: whitesmoke + status: + newColor: ghostwhite + modifyColor: navajowhite + addColor: darkslategray + errorColor: whitesmoke + highlightcolor: dimgray + killColor: slategray + completedColor: gray + title: + fgColor: ghostwhite + highlightColor: navajowhite + counterColor: navajowhite + filterColor: slategray table: fgColor: white bgColor: black @@ -24,23 +39,11 @@ k9s: fgColor: darkgray bgColor: black sorterColor: white - status: - newColor: ghostwhite - modifyColor: navajowhite - addColor: darkslategray - errorColor: whitesmoke - highlightcolor: dimgray - killColor: slategray - completedColor: gray - title: - fgColor: ghostwhite - highlightColor: navajowhite - counterColor: navajowhite - filterColor: slategray - yaml: - keyColor: ghostwhite - colorColor: slategray - valueColor: navajowhite - logs: - fgColor: ghostwhite - bgColor: black \ No newline at end of file + views: + yaml: + keyColor: ghostwhite + colorColor: slategray + valueColor: navajowhite + logs: + fgColor: ghostwhite + bgColor: black diff --git a/skins/in_the_navy.yml b/skins/in_the_navy.yml index 52155e06..0a7762d6 100644 --- a/skins/in_the_navy.yml +++ b/skins/in_the_navy.yml @@ -1,22 +1,38 @@ k9s: - fgColor: dodgerblue - bgColor: white - logoColor: blue + body: + fgColor: dodgerblue + bgColor: white + logoColor: blue info: fgColor: lightskyblue sectionColor: steelblue - border: - fgColor: dodgerblue - bgColor: darkblue - focusColor: aliceblue - menu: - fgColor: darkblue - keyColor: cornflowerblue - numKeyColor: cadetblue - crumb: - fgColor: white - bgColor: steelblue - activeColor: skyblue + frame: + border: + fgColor: dodgerblue + bgColor: darkblue + focusColor: aliceblue + menu: + fgColor: darkblue + keyColor: cornflowerblue + numKeyColor: cadetblue + crumbs: + fgColor: white + bgColor: steelblue + activeColor: skyblue + status: + newColor: blue + modifyColor: powderblue + addColor: lightskyblue + errorColor: indianred + highlightcolor: royalblue + killColor: slategray + completedColor: gray + title: + fgColor: aqua + bgColor: darkblue + highlightColor: skyblue + counterColor: slateblue + filterColor: slategray table: fgColor: blue bgColor: darkblue @@ -25,24 +41,11 @@ k9s: fgColor: white bgColor: darkblue sorterColor: orange - status: - newColor: blue - modifyColor: powderblue - addColor: lightskyblue - errorColor: indianred - highlightcolor: royalblue - killColor: slategray - completedColor: gray - title: - fgColor: aqua - bgColor: darkblue - highlightColor: skyblue - counterColor: slateblue - filterColor: slategray - yaml: - keyColor: steelblue - colorColor: blue - valueColor: royalblue - logs: - fgColor: white - bgColor: darkblue + views: + yaml: + keyColor: steelblue + colorColor: blue + valueColor: royalblue + logs: + fgColor: white + bgColor: darkblue diff --git a/skins/stock.yml b/skins/stock.yml index ec808b02..6f42d942 100644 --- a/skins/stock.yml +++ b/skins/stock.yml @@ -1,21 +1,36 @@ k9s: - fgColor: dodgerblue - bgColor: black - logoColor: orange + body: + fgColor: dodgerblue + bgColor: black + logoColor: orange info: fgColor: white sectionColor: dodgerblue - border: - fgColor: dodgerblue - focusColor: aqua - menu: - fgColor: white - keyColor: dodgerblue - numKeyColor: fuchsia - crumb: - fgColor: black - bgColor: steelblue - activeColor: orange + frame: + border: + fgColor: dodgerblue + focusColor: aqua + menu: + fgColor: white + keyColor: dodgerblue + numKeyColor: fuchsia + crumbs: + fgColor: black + bgColor: steelblue + activeColor: orange + status: + newColor: lightskyblue + modifyColor: greenyellow + addColor: white + errorColor: orangered + highlightcolor: aqua + killColor: mediumpurple + completedColor: gray + title: + fgColor: aqua + highlightColor: fuchsia + counterColor: papayawhip + filterColor: steelblue table: fgColor: blue bgColor: black @@ -24,23 +39,11 @@ k9s: fgColor: white bgColor: black sorterColor: orange - status: - newColor: lightskyblue - modifyColor: greenyellow - addColor: white - errorColor: orangered - highlightcolor: aqua - killColor: mediumpurple - completedColor: gray - title: - fgColor: aqua - highlightColor: fuchsia - counterColor: papayawhip - filterColor: steelblue - yaml: - keyColor: steelblue - colonColor: white - valueColor: papayawhip - logs: - fgColor: white - bgColor: black \ No newline at end of file + views: + yaml: + keyColor: steelblue + colonColor: white + valueColor: papayawhip + logs: + fgColor: white + bgColor: black