From 8ba42ec2bc6ae38885c500b5fbade157bbf532f4 Mon Sep 17 00:00:00 2001 From: Albert Gustavsson Date: Tue, 19 Nov 2024 07:52:31 +0100 Subject: [PATCH] Make menu foreground style configurable through skins --- internal/config/styles.go | 28 +++++++++++++++++++++++++--- internal/ui/menu.go | 6 ++++-- skins/stock.yaml | 1 + 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/internal/config/styles.go b/internal/config/styles.go index 604cfee938..3e3b4e8202 100644 --- a/internal/config/styles.go +++ b/internal/config/styles.go @@ -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. diff --git a/internal/ui/menu.go b/internal/ui/menu.go index 17466bb8c1..8c96fc8cfb 100644 --- a/internal/ui/menu.go +++ b/internal/ui/menu.go @@ -18,7 +18,7 @@ import ( ) const ( - menuIndexFmt = " [key:-:b]<%d> [fg:-:-]%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) } diff --git a/skins/stock.yaml b/skins/stock.yaml index 89b8b9d51a..5c448a6dba 100644 --- a/skins/stock.yaml +++ b/skins/stock.yaml @@ -30,6 +30,7 @@ k9s: focusColor: aqua menu: fgColor: white + fgStyle: dim keyColor: dodgerblue numKeyColor: fuchsia crumbs: