reworked skins

mine
derailed 2019-06-20 09:32:39 -06:00
parent 6c9943c68c
commit 1415fedd6a
30 changed files with 403 additions and 333 deletions

View File

@ -324,6 +324,7 @@ Below is a sample skin file, more skins would be available in the skins director
# InTheNavy Skin...
k9s:
# General K9s styles
body:
fgColor: dodgerblue
bgColor: white
logoColor: blue
@ -331,6 +332,7 @@ k9s:
info:
fgColor: lightskyblue
sectionColor: steelblue
frame:
# Borders styles.
border:
fgColor: dodgerblue
@ -342,21 +344,10 @@ k9s:
# Used for favorite namespaces
numKeyColor: cadetblue
# CrumbView attributes for history navigation.
crumb:
crumbs:
fgColor: white
bgColor: steelblue
# Active view settings
activeColor: skyblue
# TableView attributes.
table:
fgColor: blue
bgColor: darkblue
cursorColor: aqua
# Header row styles.
header:
fgColor: white
bgColor: darkblue
sorterColor: orange
# Resource status and update styles
status:
newColor: blue
@ -373,6 +364,17 @@ k9s:
highlightColor: skyblue
counterColor: slateblue
filterColor: slategray
# TableView attributes.
table:
fgColor: blue
bgColor: darkblue
cursorColor: aqua
# Header row styles.
header:
fgColor: white
bgColor: darkblue
sorterColor: orange
views:
# YAML info styles.
yaml:
keyColor: steelblue

View File

@ -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 {
// Body tracks body styles.
Body 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"`
}
// 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.
@ -93,7 +99,7 @@ type (
FgColor string `yaml:"fgColor"`
BgColor string `yaml:"bgColor"`
CursorColor string `yaml:"cursorColor"`
Header *TableHeader `yaml:"header"`
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(),
func newStyle() Style {
return Style{
Body: newBody(),
Frame: newFrame(),
Info: newInfo(),
Menu: newMenu(),
Crumb: newCrumb(),
Table: newTable(),
Status: newStatus(),
Views: newViews(),
}
}
func newViews() Views {
return Views{
Yaml: newYaml(),
Log: newLog(),
}
}
func newStatus() *Status {
return &Status{
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.

View File

@ -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)

View File

@ -1,10 +1,12 @@
k9s:
body:
fgColor: white
bgColor: black
logoColor: white
info:
fgColor: navajowhite
sectionColor: white
frame:
border:
fgColor: white
focusColor: white
@ -16,14 +18,6 @@ k9s:
fgColor: black
bgColor: navajowhite
activeColor: whitesmoke
table:
fgColor: white
bgColor: black
cursorColor: white
header:
fgColor: darkgray
bgColor: black
sorterColor: white
status:
newColor: ghostwhite
modifyColor: navajowhite
@ -37,3 +31,11 @@ k9s:
highlightColor: navajowhite
counterColor: navajowhite
filterColor: slategray
table:
fgColor: white
bgColor: black
cursorColor: white
header:
fgColor: darkgray
bgColor: black
sorterColor: white

View File

@ -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")
}

View File

@ -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

View File

@ -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

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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) {

View File

@ -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)

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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")

View File

@ -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")

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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))
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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 {

View File

@ -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))
}
}

View File

@ -1,10 +1,12 @@
k9s:
body:
fgColor: white
bgColor: black
logoColor: white
info:
fgColor: navajowhite
sectionColor: white
frame:
border:
fgColor: white
focusColor: white
@ -12,18 +14,10 @@ k9s:
fgColor: white
keyColor: white
numKeyColor: navajowhite
crumb:
crumbs:
fgColor: black
bgColor: navajowhite
activeColor: whitesmoke
table:
fgColor: white
bgColor: black
cursorColor: white
header:
fgColor: darkgray
bgColor: black
sorterColor: white
status:
newColor: ghostwhite
modifyColor: navajowhite
@ -37,6 +31,15 @@ k9s:
highlightColor: navajowhite
counterColor: navajowhite
filterColor: slategray
table:
fgColor: white
bgColor: black
cursorColor: white
header:
fgColor: darkgray
bgColor: black
sorterColor: white
views:
yaml:
keyColor: ghostwhite
colorColor: slategray

View File

@ -1,10 +1,12 @@
k9s:
body:
fgColor: dodgerblue
bgColor: white
logoColor: blue
info:
fgColor: lightskyblue
sectionColor: steelblue
frame:
border:
fgColor: dodgerblue
bgColor: darkblue
@ -13,18 +15,10 @@ k9s:
fgColor: darkblue
keyColor: cornflowerblue
numKeyColor: cadetblue
crumb:
crumbs:
fgColor: white
bgColor: steelblue
activeColor: skyblue
table:
fgColor: blue
bgColor: darkblue
cursorColor: aqua
header:
fgColor: white
bgColor: darkblue
sorterColor: orange
status:
newColor: blue
modifyColor: powderblue
@ -39,6 +33,15 @@ k9s:
highlightColor: skyblue
counterColor: slateblue
filterColor: slategray
table:
fgColor: blue
bgColor: darkblue
cursorColor: aqua
header:
fgColor: white
bgColor: darkblue
sorterColor: orange
views:
yaml:
keyColor: steelblue
colorColor: blue

View File

@ -1,10 +1,12 @@
k9s:
body:
fgColor: dodgerblue
bgColor: black
logoColor: orange
info:
fgColor: white
sectionColor: dodgerblue
frame:
border:
fgColor: dodgerblue
focusColor: aqua
@ -12,18 +14,10 @@ k9s:
fgColor: white
keyColor: dodgerblue
numKeyColor: fuchsia
crumb:
crumbs:
fgColor: black
bgColor: steelblue
activeColor: orange
table:
fgColor: blue
bgColor: black
cursorColor: aqua
header:
fgColor: white
bgColor: black
sorterColor: orange
status:
newColor: lightskyblue
modifyColor: greenyellow
@ -37,6 +31,15 @@ k9s:
highlightColor: fuchsia
counterColor: papayawhip
filterColor: steelblue
table:
fgColor: blue
bgColor: black
cursorColor: aqua
header:
fgColor: white
bgColor: black
sorterColor: orange
views:
yaml:
keyColor: steelblue
colonColor: white