templates: allow layered fg & bg color for inline styles

If a user style has no fg and/or no bg color defined, use the color from
the underlying style.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
Robin Jarry
2023-03-02 23:49:37 +01:00
parent 41942bb97d
commit ab8f433e17

View File

@@ -242,13 +242,15 @@ func (rb *RuneBuffer) ApplyStyle(style tcell.Style) {
// attributes
func (rb *RuneBuffer) ApplyAttrs(style tcell.Style) {
for _, sr := range rb.buf {
if sr.Style == tcell.StyleDefault {
sr.Style = style
continue
}
_, _, srAttrs := sr.Style.Decompose()
_, _, attrs := style.Decompose()
fg, bg, attrs := style.Decompose()
sr.Style = sr.Style.Attributes(srAttrs | attrs)
if fg != tcell.ColorDefault {
sr.Style = sr.Style.Foreground(fg)
}
if bg != tcell.ColorDefault {
sr.Style = sr.Style.Background(bg)
}
}
}