Skip to content

Commit 66b5c11

Browse files
authored
Merge pull request #264 from dyc3/more-font-attrs
add remaining font modifiers: strikethrough, inverse, blink
2 parents add3cff + 93ddcf4 commit 66b5c11

File tree

6 files changed

+55
-5
lines changed

6 files changed

+55
-5
lines changed

cell/cell.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type Options struct {
2929
Italic bool
3030
Underline bool
3131
Strikethrough bool
32+
Inverse bool
33+
Blink bool
3234
}
3335

3436
// Set allows existing options to be passed as an option.
@@ -88,9 +90,23 @@ func Underline() Option {
8890
})
8991
}
9092

91-
// Strikethrough strikes through the cell's text. Currently a no-op until tcell is updated to >= v2.0.0
93+
// Strikethrough strikes through the cell's text. Only works when using the tcell backend.
9294
func Strikethrough() Option {
9395
return option(func(co *Options) {
9496
co.Strikethrough = true
9597
})
9698
}
99+
100+
// Inverse inverts the colors of the cell's text.
101+
func Inverse() Option {
102+
return option(func(co *Options) {
103+
co.Inverse = true
104+
})
105+
}
106+
107+
// Blink makes the cell's text blink. Only works when using the tcell backend.
108+
func Blink() Option {
109+
return option(func(co *Options) {
110+
co.Blink = true
111+
})
112+
}

cell/cell_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,16 @@ func TestNewOptions(t *testing.T) {
8080
Italic(),
8181
Underline(),
8282
Strikethrough(),
83+
Inverse(),
84+
Blink(),
8385
},
8486
want: &Options{
8587
Bold: true,
8688
Italic: true,
8789
Underline: true,
8890
Strikethrough: true,
91+
Inverse: true,
92+
Blink: true,
8993
},
9094
},
9195
}

terminal/tcell/cell_options.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ func cellOptsToStyle(opts *cell.Options, colorMode terminalapi.ColorMode) tcell.
6363
fg := cellColor(colorToMode(opts.FgColor, colorMode))
6464
bg := cellColor(colorToMode(opts.BgColor, colorMode))
6565

66-
// FIXME: tcell doesn't have a strikethrough style option until #254 is resolved.
67-
st = st.Foreground(fg).Background(bg).Bold(opts.Bold).Italic(opts.Italic).Underline(opts.Underline)
66+
st = st.Foreground(fg).
67+
Background(bg).
68+
Bold(opts.Bold).
69+
Italic(opts.Italic).
70+
Underline(opts.Underline).
71+
StrikeThrough(opts.Strikethrough).
72+
Reverse(opts.Inverse).
73+
Blink(opts.Blink)
6874
return st
6975
}

terminal/tcell/cell_options_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,21 @@ func TestCellOptsToStyle(t *testing.T) {
310310
opts: cell.Options{Underline: true},
311311
want: tcell.StyleDefault.Underline(true),
312312
},
313+
{
314+
colorMode: terminalapi.ColorModeNormal,
315+
opts: cell.Options{Strikethrough: true},
316+
want: tcell.StyleDefault.StrikeThrough(true),
317+
},
318+
{
319+
colorMode: terminalapi.ColorModeNormal,
320+
opts: cell.Options{Inverse: true},
321+
want: tcell.StyleDefault.Reverse(true),
322+
},
323+
{
324+
colorMode: terminalapi.ColorModeNormal,
325+
opts: cell.Options{Blink: true},
326+
want: tcell.StyleDefault.Blink(true),
327+
},
313328
}
314329

315330
for _, tc := range tests {

terminal/termbox/cell_options.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,24 @@ func cellOptsToFg(opts *cell.Options) (tbx.Attribute, error) {
4949
if opts.Bold {
5050
a |= tbx.AttrBold
5151
}
52-
// FIXME: Termbox doesn't have an italics attribute
52+
// Termbox doesn't have an italics attribute
5353
if opts.Italic {
5454
return 0, errors.New("Termbox: Unsupported attribute: Italic")
5555
}
5656
if opts.Underline {
5757
a |= tbx.AttrUnderline
5858
}
59-
// FIXME: Termbox doesn't have a strikethrough attribute
59+
// Termbox doesn't have a strikethrough attribute
6060
if opts.Strikethrough {
6161
return 0, errors.New("Termbox: Unsupported attribute: Strikethrough")
6262
}
63+
if opts.Inverse {
64+
a |= tbx.AttrReverse
65+
}
66+
// Termbox doesn't have a blink attribute
67+
if opts.Blink {
68+
return 0, errors.New("Termbox: Unsupported attribute: Blink")
69+
}
6370
return a, nil
6471
}
6572

terminal/termbox/cell_options_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ func TestCellFontModifier(t *testing.T) {
6060
{cell.Options{Underline: true}, tbx.AttrUnderline, false},
6161
{cell.Options{Italic: true}, 0, true},
6262
{cell.Options{Strikethrough: true}, 0, true},
63+
{cell.Options{Inverse: true}, tbx.AttrReverse, false},
64+
{cell.Options{Blink: true}, 0, true},
6365
}
6466

6567
for _, tc := range tests {

0 commit comments

Comments
 (0)