mirror of https://github.com/rivo/tview.git
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:
parent
cc84c982fc
commit
b4fd66d458
31
textview.go
31
textview.go
|
@ -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++ {
|
||||||
|
|
Loading…
Reference in New Issue