diff --git a/cell/cell_test.go b/cell/cell_test.go index 153c5cc..329fdb7 100644 --- a/cell/cell_test.go +++ b/cell/cell_test.go @@ -27,6 +27,7 @@ func TestNewOptions(t *testing.T) { want *Options }{ { + desc: "no provided options", want: &Options{}, }, @@ -72,6 +73,21 @@ func TestNewOptions(t *testing.T) { BgColor: ColorMagenta, }, }, + { + desc: "setting font attributes", + opts: []Option{ + Bold(), + Italic(), + Underline(), + Strikethrough(), + }, + want: &Options{ + Bold: true, + Italic: true, + Underline: true, + Strikethrough: true, + }, + }, } for _, tc := range tests { diff --git a/terminal/tcell/cell_options.go b/terminal/tcell/cell_options.go index 7195181..d783747 100644 --- a/terminal/tcell/cell_options.go +++ b/terminal/tcell/cell_options.go @@ -57,7 +57,7 @@ func cellOptsToStyle(opts *cell.Options, colorMode terminalapi.ColorMode) tcell. fg = fixColor(fg, colorMode) bg = fixColor(bg, colorMode) - // FIXME: tcell doesn't have a strikethrough style option + // FIXME: tcell doesn't have a strikethrough style option until #254 is resolved. st = st.Foreground(fg).Background(bg).Bold(opts.Bold).Italic(opts.Italic).Underline(opts.Underline) return st } diff --git a/terminal/termbox/cell_options.go b/terminal/termbox/cell_options.go index 9f2a638..547c7e3 100644 --- a/terminal/termbox/cell_options.go +++ b/terminal/termbox/cell_options.go @@ -31,22 +31,21 @@ func cellColor(c cell.Color) tbx.Attribute { // cellOptsToFg converts the cell options to the termbox foreground attribute. func cellOptsToFg(opts *cell.Options) (tbx.Attribute, error) { a := cellColor(opts.FgColor) - var err error if opts.Bold { a |= tbx.AttrBold } // FIXME: Termbox doesn't have an italics attribute if opts.Italic { - err = errors.New("Termbox: Unsupported attribute: Italic") + return 0, errors.New("Termbox: Unsupported attribute: Italic") } if opts.Underline { a |= tbx.AttrUnderline } // FIXME: Termbox doesn't have a strikethrough attribute if opts.Strikethrough { - err = errors.New("Termbox: Unsupported attribute: Strikethrough") + return 0, errors.New("Termbox: Unsupported attribute: Strikethrough") } - return a, err + return a, nil } // cellOptsToBg converts the cell options to the termbox background attribute. diff --git a/terminal/termbox/cell_options_test.go b/terminal/termbox/cell_options_test.go index 66d9e1d..6c40426 100644 --- a/terminal/termbox/cell_options_test.go +++ b/terminal/termbox/cell_options_test.go @@ -52,18 +52,24 @@ func TestCellColor(t *testing.T) { func TestCellFontModifier(t *testing.T) { tests := []struct { - opt cell.Options - want tbx.Attribute + opt cell.Options + want tbx.Attribute + wantErr bool }{ - {cell.Options{Bold: true}, tbx.AttrBold}, - {cell.Options{Underline: true}, tbx.AttrUnderline}, + {cell.Options{Bold: true}, tbx.AttrBold, false}, + {cell.Options{Underline: true}, tbx.AttrUnderline, false}, + {cell.Options{Italic: true}, 0, true}, + {cell.Options{Strikethrough: true}, 0, true}, } for _, tc := range tests { t.Run(fmt.Sprintf("%v", tc.opt), func(t *testing.T) { got, err := cellOptsToFg(&tc.opt) + if (err != nil) != tc.wantErr { + t.Errorf("cellOptsToFg(%v) => unexpected error: %v, wantErr: %v", tc.opt, err, tc.wantErr) + } if err != nil { - t.Errorf("cellOptsToFg(%v) failed: %s", tc.opt, err) + return } if got != tc.want { t.Errorf("cellOptsToFg(%v) => got %v, want %v", tc.opt, got, tc.want)