Fixed style calculation in TextView which led to unwanted artefacts when the default terminal background color was not black. Fixes #91

This commit is contained in:
Oliver 2018-04-07 13:28:32 +02:00
parent cc84c982fc
commit b4fd66d458
1 changed files with 19 additions and 12 deletions

View File

@ -811,22 +811,29 @@ func (t *TextView) Draw(screen tcell.Screen) {
// Do we highlight this character? // Do we highlight this character?
finalStyle := style finalStyle := style
var highlighted bool
if len(regionID) > 0 { if len(regionID) > 0 {
if _, ok := t.highlights[regionID]; ok { if _, ok := t.highlights[regionID]; ok {
fg, bg, _ := finalStyle.Decompose() highlighted = true
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)
} }
} }
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. // Draw the character.
for offset := 0; offset < chWidth; offset++ { for offset := 0; offset < chWidth; offset++ {