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
Inverse bool
Blink bool
Dim bool
}
// Set allows existing options to be passed as an option.
@ -110,3 +111,10 @@ func Blink() Option {
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(),
Inverse(),
Blink(),
Dim(),
},
want: &Options{
Bold: true,
@ -90,6 +91,7 @@ func TestNewOptions(t *testing.T) {
Strikethrough: true,
Inverse: true,
Blink: true,
Dim: true,
},
},
}

View File

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

View File

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

View File

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

View File

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