1
0
mirror of https://github.com/mum4k/termdash.git synced 2025-04-25 13:48:50 +08:00

have the termbox backend return an error when attempting to use italics or strikethrough

This commit is contained in:
“Carson 2020-11-13 02:15:57 -05:00
parent 50310f4d29
commit f501a14afa
2 changed files with 21 additions and 4 deletions

View File

@ -17,6 +17,8 @@ package termbox
// cell_options.go converts termdash cell options to the termbox format.
import (
"errors"
"github.com/mum4k/termdash/cell"
tbx "github.com/nsf/termbox-go"
)
@ -27,17 +29,24 @@ func cellColor(c cell.Color) tbx.Attribute {
}
// cellOptsToFg converts the cell options to the termbox foreground attribute.
func cellOptsToFg(opts *cell.Options) tbx.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")
}
if opts.Underline {
a |= tbx.AttrUnderline
}
// FIXME: Termbox doesn't have a strikethrough attribute
return a
if opts.Strikethrough {
err = errors.New("Termbox: Unsupported attribute: Strikethrough")
}
return a, err
}
// cellOptsToBg converts the cell options to the termbox background attribute.

View File

@ -105,7 +105,11 @@ func (t *Terminal) Size() image.Point {
// Clear implements terminalapi.Terminal.Clear.
func (t *Terminal) Clear(opts ...cell.Option) error {
o := cell.NewOptions(opts...)
return tbx.Clear(cellOptsToFg(o), cellOptsToBg(o))
fg, err := cellOptsToFg(o)
if err != nil {
return err
}
return tbx.Clear(fg, cellOptsToBg(o))
}
// Flush implements terminalapi.Terminal.Flush.
@ -126,7 +130,11 @@ func (t *Terminal) HideCursor() {
// SetCell implements terminalapi.Terminal.SetCell.
func (t *Terminal) SetCell(p image.Point, r rune, opts ...cell.Option) error {
o := cell.NewOptions(opts...)
tbx.SetCell(p.X, p.Y, r, cellOptsToFg(o), cellOptsToBg(o))
fg, err := cellOptsToFg(o)
if err != nil {
return err
}
tbx.SetCell(p.X, p.Y, r, fg, cellOptsToBg(o))
return nil
}