Skip to content

Commit

Permalink
Make menu foreground style configurable through skins
Browse files Browse the repository at this point in the history
  • Loading branch information
albertgustavsson committed Nov 19, 2024
1 parent aa80b8c commit 8ba42ec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
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:-:-]%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

0 comments on commit 8ba42ec

Please sign in to comment.