aboutsummaryrefslogtreecommitdiffstats
path: root/lib/parse
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-03-12 10:26:20 +0100
committerRobin Jarry <robin@jarry.cc>2023-03-31 21:02:14 +0200
commitae4d742c5a90091c1229639a8480830805ac105d (patch)
tree5e018f6e4e21562a4f49f8726b028c697ec2222b /lib/parse
parent86441411f46ba067cb445e6590b8d12cd20c4490 (diff)
downloadaerc-ae4d742c5a90091c1229639a8480830805ac105d.tar.gz
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 <robin@jarry.cc> Tested-by: Bence Ferdinandy <bence@ferdinandy.com>
Diffstat (limited to 'lib/parse')
-rw-r--r--lib/parse/ansi.go15
1 files changed, 8 insertions, 7 deletions
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)
}
}