templates: fix layered fg & bg color for inline styles

The logic was inverted. The style argument is actually the "under" layer
style. Each character in the RuneBuffer style must be applied on *top*
of it, not the other way around.

Use colors from style and override them with each character's colors if
they are set. Keep attributes handling unchanged.

Fixes: ab8f433e17 ("templates: allow layered fg & bg color for inline styles")
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
This commit is contained in:
Robin Jarry
2023-03-12 10:26:20 +01:00
parent 86441411f4
commit ae4d742c5a

View File

@@ -241,16 +241,17 @@ func (rb *RuneBuffer) ApplyStyle(style tcell.Style) {
// ApplyAttrs applies the style, and if another style is present ORs the
// attributes
func (rb *RuneBuffer) ApplyAttrs(style tcell.Style) {
fg, bg, attrs := style.Decompose()
for _, sr := range rb.buf {
_, _, srAttrs := sr.Style.Decompose()
fg, bg, attrs := style.Decompose()
sr.Style = sr.Style.Attributes(srAttrs | attrs)
if fg != tcell.ColorDefault {
sr.Style = sr.Style.Foreground(fg)
srFg, srBg, srAttrs := sr.Style.Decompose()
if srFg == tcell.ColorDefault {
srFg = fg
}
if bg != tcell.ColorDefault {
sr.Style = sr.Style.Background(bg)
if srBg == tcell.ColorDefault {
srBg = bg
}
sr.Style = sr.Style.Attributes(attrs | srAttrs).
Foreground(srFg).Background(srBg)
}
}