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

Make menu foreground style configurable through skins #2965

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 25 additions & 3 deletions internal/config/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ type StyleListener interface {
StylesChanged(*Styles)
}

type TextStyle string

const (
TextStyleNormal TextStyle = "normal"
TextStyleBold TextStyle = "bold"
TextStyleDim TextStyle = "dim"
)

func (ts TextStyle) ToShortString() string {
switch ts {
case TextStyleNormal:
return "-"
case TextStyleBold:
return "b"
case TextStyleDim:
return "d"
default:
return "d"
}
}

type (
// Styles tracks K9s styling options.
Styles struct {
Expand Down Expand Up @@ -200,9 +221,10 @@ type (

// Menu tracks menu styles.
Menu struct {
FgColor Color `json:"fgColor" yaml:"fgColor"`
KeyColor Color `json:"keyColor" yaml:"keyColor"`
NumKeyColor Color `json:"numKeyColor" yaml:"numKeyColor"`
FgColor Color `json:"fgColor" yaml:"fgColor"`
FgStyle TextStyle `json:"fgStyle" yaml:"fgStyle"`
KeyColor Color `json:"keyColor" yaml:"keyColor"`
NumKeyColor Color `json:"numKeyColor" yaml:"numKeyColor"`
}

// Charts tracks charts styles.
Expand Down
6 changes: 4 additions & 2 deletions internal/ui/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

const (
menuIndexFmt = " [key:-:b]<%d> [fg:-:d]%s "
menuIndexFmt = " [key:-:b]<%d> [fg:-:fgstyle]%s "
maxRows = 6
)

Expand Down Expand Up @@ -199,15 +199,17 @@ func formatNSMenu(i int, name string, styles config.Frame) string {
fmat := strings.Replace(menuIndexFmt, "[key", "["+styles.Menu.NumKeyColor.String(), 1)
fmat = strings.Replace(fmat, ":bg:", ":"+styles.Title.BgColor.String()+":", -1)
fmat = strings.Replace(fmat, "[fg", "["+styles.Menu.FgColor.String(), 1)
fmat = strings.Replace(fmat, "fgstyle]", styles.Menu.FgStyle.ToShortString()+"]", 1)

return fmt.Sprintf(fmat, i, name)
}

func formatPlainMenu(h model.MenuHint, size int, styles config.Frame) string {
menuFmt := " [key:-:b]%-" + strconv.Itoa(size+2) + "s [fg:-:d]%s "
menuFmt := " [key:-:b]%-" + strconv.Itoa(size+2) + "s [fg:-:fgstyle]%s "
fmat := strings.Replace(menuFmt, "[key", "["+styles.Menu.KeyColor.String(), 1)
fmat = strings.Replace(fmat, "[fg", "["+styles.Menu.FgColor.String(), 1)
fmat = strings.Replace(fmat, ":bg:", ":"+styles.Title.BgColor.String()+":", -1)
fmat = strings.Replace(fmat, "fgstyle]", styles.Menu.FgStyle.ToShortString()+"]", 1)

return fmt.Sprintf(fmat, ToMnemonic(h.Mnemonic), h.Description)
}
1 change: 1 addition & 0 deletions skins/stock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ k9s:
focusColor: aqua
menu:
fgColor: white
fgStyle: dim
keyColor: dodgerblue
numKeyColor: fuchsia
crumbs:
Expand Down