From ae4d742c5a90091c1229639a8480830805ac105d Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Sun, 12 Mar 2023 10:26:20 +0100 Subject: 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: ab8f433e1739 ("templates: allow layered fg & bg color for inline styles") Signed-off-by: Robin Jarry Tested-by: Bence Ferdinandy --- lib/parse/ansi.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'lib/parse/ansi.go') diff --git a/lib/parse/ansi.go b/lib/parse/ansi.go index 8b448d77..11424cc5 100644 --- a/lib/parse/ansi.go +++ b/lib/parse/ansi.go @@ -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) } } -- cgit