Make menu foreground style configurable through skins (#2965)

* Make menu foreground style configurable through skins

* Added menu fgStyle info to README

---------

Co-authored-by: Fernand Galiana <fernand.galiana@gmail.com>
mine
Albert Gustavsson 2025-02-16 01:46:03 +01:00 committed by GitHub
parent cc1c86ccb4
commit ea162b06e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 5 deletions

View File

@ -1030,6 +1030,8 @@ k9s:
# MenuView attributes and styles.
menu:
fgColor: darkblue
# Style of menu text. Supported options are "dim" (default), "normal", and "bold"
fgStyle: dim
keyColor: cornflowerblue
# Used for favorite namespaces
numKeyColor: cadetblue

View File

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

View File

@ -18,7 +18,7 @@ import (
)
const (
menuIndexFmt = " [key:-:b]<%d> [fg:-:d]%s "
menuIndexFmt = " [key:-:b]<%d> [fg:-:fgstyle]%s "
maxRows = 6
)
@ -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)
}

View File

@ -30,6 +30,7 @@ k9s:
focusColor: aqua
menu:
fgColor: white
fgStyle: dim
keyColor: dodgerblue
numKeyColor: fuchsia
crumbs: