diff --git a/pkg/gui/style/basic_styles.go b/pkg/gui/style/basic_styles.go index 59bd907ff..ba41bd01b 100644 --- a/pkg/gui/style/basic_styles.go +++ b/pkg/gui/style/basic_styles.go @@ -34,6 +34,7 @@ var ( AttrUnderline = New().SetUnderline() AttrBold = New().SetBold() + AttrDim = New().SetDim() ColorMap = map[string]struct { Foreground TextStyle diff --git a/pkg/gui/style/decoration.go b/pkg/gui/style/decoration.go index b5d95b645..3fcb3998d 100644 --- a/pkg/gui/style/decoration.go +++ b/pkg/gui/style/decoration.go @@ -4,6 +4,7 @@ import "github.com/gookit/color" type Decoration struct { bold bool + dim bool underline bool reverse bool strikethrough bool @@ -13,6 +14,10 @@ func (d *Decoration) SetBold() { d.bold = true } +func (d *Decoration) SetDim() { + d.dim = true +} + func (d *Decoration) SetUnderline() { d.underline = true } @@ -26,12 +31,16 @@ func (d *Decoration) SetStrikethrough() { } func (d Decoration) ToOpts() color.Opts { - opts := make([]color.Color, 0, 3) + opts := make([]color.Color, 0, 5) if d.bold { opts = append(opts, color.OpBold) } + if d.dim { + opts = append(opts, color.OpFuzzy) + } + if d.underline { opts = append(opts, color.OpUnderscore) } @@ -52,6 +61,10 @@ func (d Decoration) Merge(other Decoration) Decoration { d.bold = true } + if other.dim { + d.dim = true + } + if other.underline { d.underline = true } diff --git a/pkg/gui/style/style_test.go b/pkg/gui/style/style_test.go index 10e88883b..b43677729 100644 --- a/pkg/gui/style/style_test.go +++ b/pkg/gui/style/style_test.go @@ -68,6 +68,25 @@ func TestMerge(t *testing.T) { }, "\x1b[1mfoo\x1b[0m", }, + { + "dim attribute", + []TextStyle{AttrDim}, + TextStyle{ + decoration: Decoration{dim: true}, + Style: color.Style{color.OpFuzzy}, + }, + "\x1b[2mfoo\x1b[0m", + }, + { + "dim attribute and color", + []TextStyle{FgRed.SetDim()}, + TextStyle{ + fg: &Color{basic: &fgRed}, + decoration: Decoration{dim: true}, + Style: color.Style{fgRed, color.OpFuzzy}, + }, + "\x1b[31;2mfoo\x1b[0m", + }, { "multiple attributes", []TextStyle{AttrBold, AttrUnderline}, diff --git a/pkg/gui/style/text_style.go b/pkg/gui/style/text_style.go index 44b2fbf55..cfcb96c84 100644 --- a/pkg/gui/style/text_style.go +++ b/pkg/gui/style/text_style.go @@ -63,6 +63,12 @@ func (b TextStyle) SetBold() TextStyle { return b } +func (b TextStyle) SetDim() TextStyle { + b.decoration.SetDim() + b.Style = b.deriveStyle() + return b +} + func (b TextStyle) SetUnderline() TextStyle { b.decoration.SetUnderline() b.Style = b.deriveStyle()