From b4fd66d4584cc8f276a857f2bae256bfc1ab8e4c Mon Sep 17 00:00:00 2001 From: Oliver <480930+rivo@users.noreply.github.com> Date: Sat, 7 Apr 2018 13:28:32 +0200 Subject: [PATCH] Fixed style calculation in TextView which led to unwanted artefacts when the default terminal background color was not black. Fixes #91 --- textview.go | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/textview.go b/textview.go index a80219e..98eb2bb 100644 --- a/textview.go +++ b/textview.go @@ -811,22 +811,29 @@ func (t *TextView) Draw(screen tcell.Screen) { // Do we highlight this character? finalStyle := style + var highlighted bool if len(regionID) > 0 { if _, ok := t.highlights[regionID]; ok { - fg, bg, _ := finalStyle.Decompose() - if bg == tcell.ColorDefault { - r, g, b := fg.RGB() - c := colorful.Color{R: float64(r) / 255, G: float64(g) / 255, B: float64(b) / 255} - _, _, li := c.Hcl() - if li < .5 { - bg = tcell.ColorWhite - } else { - bg = tcell.ColorBlack - } - } - finalStyle = style.Background(fg).Foreground(bg) + highlighted = true } } + if highlighted { + fg, bg, _ := finalStyle.Decompose() + if bg == tcell.ColorDefault { + r, g, b := fg.RGB() + c := colorful.Color{R: float64(r) / 255, G: float64(g) / 255, B: float64(b) / 255} + _, _, li := c.Hcl() + if li < .5 { + bg = tcell.ColorWhite + } else { + bg = tcell.ColorBlack + } + } + finalStyle = style.Background(fg).Foreground(bg) + } else { + _, _, existingStyle, _ := screen.GetContent(x+posX, y+line-t.lineOffset) + finalStyle = overlayStyle(existingStyle, style, overwriteAttr) + } // Draw the character. for offset := 0; offset < chWidth; offset++ {