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:
parent
50310f4d29
commit
f501a14afa
@ -17,6 +17,8 @@ package termbox
|
|||||||
// cell_options.go converts termdash cell options to the termbox format.
|
// cell_options.go converts termdash cell options to the termbox format.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/mum4k/termdash/cell"
|
"github.com/mum4k/termdash/cell"
|
||||||
tbx "github.com/nsf/termbox-go"
|
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.
|
// 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)
|
a := cellColor(opts.FgColor)
|
||||||
|
var err error
|
||||||
if opts.Bold {
|
if opts.Bold {
|
||||||
a |= tbx.AttrBold
|
a |= tbx.AttrBold
|
||||||
}
|
}
|
||||||
// FIXME: Termbox doesn't have an italics attribute
|
// FIXME: Termbox doesn't have an italics attribute
|
||||||
|
if opts.Italic {
|
||||||
|
err = errors.New("Termbox: Unsupported attribute: Italic")
|
||||||
|
}
|
||||||
if opts.Underline {
|
if opts.Underline {
|
||||||
a |= tbx.AttrUnderline
|
a |= tbx.AttrUnderline
|
||||||
}
|
}
|
||||||
// FIXME: Termbox doesn't have a strikethrough attribute
|
// 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.
|
// cellOptsToBg converts the cell options to the termbox background attribute.
|
||||||
|
@ -105,7 +105,11 @@ func (t *Terminal) Size() image.Point {
|
|||||||
// Clear implements terminalapi.Terminal.Clear.
|
// Clear implements terminalapi.Terminal.Clear.
|
||||||
func (t *Terminal) Clear(opts ...cell.Option) error {
|
func (t *Terminal) Clear(opts ...cell.Option) error {
|
||||||
o := cell.NewOptions(opts...)
|
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.
|
// Flush implements terminalapi.Terminal.Flush.
|
||||||
@ -126,7 +130,11 @@ func (t *Terminal) HideCursor() {
|
|||||||
// SetCell implements terminalapi.Terminal.SetCell.
|
// SetCell implements terminalapi.Terminal.SetCell.
|
||||||
func (t *Terminal) SetCell(p image.Point, r rune, opts ...cell.Option) error {
|
func (t *Terminal) SetCell(p image.Point, r rune, opts ...cell.Option) error {
|
||||||
o := cell.NewOptions(opts...)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user