add tcell's dim text style

This commit is contained in:
Aniket Teredesai 2022-07-01 09:22:23 +05:30
parent ab8e6dd194
commit bb460d221d
6 changed files with 23 additions and 1 deletions

View File

@ -31,6 +31,7 @@ type Options struct {
Strikethrough bool Strikethrough bool
Inverse bool Inverse bool
Blink bool Blink bool
Dim bool
} }
// Set allows existing options to be passed as an option. // Set allows existing options to be passed as an option.
@ -110,3 +111,10 @@ func Blink() Option {
co.Blink = true co.Blink = true
}) })
} }
// Dim makes the cell foreground color dim. Only works when using the tcell backend.
func Dim() Option {
return option(func(co *Options) {
co.Dim = true
})
}

View File

@ -82,6 +82,7 @@ func TestNewOptions(t *testing.T) {
Strikethrough(), Strikethrough(),
Inverse(), Inverse(),
Blink(), Blink(),
Dim(),
}, },
want: &Options{ want: &Options{
Bold: true, Bold: true,
@ -90,6 +91,7 @@ func TestNewOptions(t *testing.T) {
Strikethrough: true, Strikethrough: true,
Inverse: true, Inverse: true,
Blink: true, Blink: true,
Dim: true,
}, },
}, },
} }

View File

@ -70,6 +70,7 @@ func cellOptsToStyle(opts *cell.Options, colorMode terminalapi.ColorMode) tcell.
Underline(opts.Underline). Underline(opts.Underline).
StrikeThrough(opts.Strikethrough). StrikeThrough(opts.Strikethrough).
Reverse(opts.Inverse). Reverse(opts.Inverse).
Blink(opts.Blink) Blink(opts.Blink).
Dim(opts.Dim)
return st return st
} }

View File

@ -325,6 +325,11 @@ func TestCellOptsToStyle(t *testing.T) {
opts: cell.Options{Blink: true}, opts: cell.Options{Blink: true},
want: tcell.StyleDefault.Blink(true), want: tcell.StyleDefault.Blink(true),
}, },
{
colorMode: terminalapi.ColorModeNormal,
opts: cell.Options{Dim: true},
want: tcell.StyleDefault.Dim(true),
},
} }
for _, tc := range tests { for _, tc := range tests {

View File

@ -67,6 +67,11 @@ func cellOptsToFg(opts *cell.Options) (tbx.Attribute, error) {
if opts.Blink { if opts.Blink {
return 0, errors.New("Termbox: Unsupported attribute: Blink") return 0, errors.New("Termbox: Unsupported attribute: Blink")
} }
if opts.Dim {
return 0, errors.New("Termbox: Unsupported attribute: Dim")
}
return a, nil return a, nil
} }

View File

@ -62,6 +62,7 @@ func TestCellFontModifier(t *testing.T) {
{cell.Options{Strikethrough: true}, 0, true}, {cell.Options{Strikethrough: true}, 0, true},
{cell.Options{Inverse: true}, tbx.AttrReverse, false}, {cell.Options{Inverse: true}, tbx.AttrReverse, false},
{cell.Options{Blink: true}, 0, true}, {cell.Options{Blink: true}, 0, true},
{cell.Options{Dim: true}, 0, true},
} }
for _, tc := range tests { for _, tc := range tests {