Add a dim text style

A later commit shows the hashes of commits outside the bisect range in a
dimmer variant of the default text color. A darker shade of a terminal
palette color can't be derived, because we don't know what the palette
is, so leave the shading to the terminal and use its faint attribute,
SGR 2. In gookit/color that attribute is called OpFuzzy.

Terminals that don't implement SGR 2 render the text in its normal color.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-09-27 08:16:06 +02:00
co-authored by Claude Opus 5
parent 0ca4fdefba
commit 679fe58e8e
4 changed files with 40 additions and 1 deletions
+1
View File
@@ -34,6 +34,7 @@ var (
AttrUnderline = New().SetUnderline()
AttrBold = New().SetBold()
AttrDim = New().SetDim()
ColorMap = map[string]struct {
Foreground TextStyle
+14 -1
View File
@@ -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
}
+19
View File
@@ -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},
+6
View File
@@ -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()