refactor(ansi): do not print when invisible

This commit is contained in:
Jan De Dobbeleer 2023-01-05 13:32:50 +01:00 committed by Jan De Dobbeleer
parent 850787cd6f
commit c1bf3a16fe
2 changed files with 17 additions and 3 deletions

View file

@ -89,6 +89,7 @@ type Writer struct {
currentBackground Color
runes []rune
transparent bool
invisible bool
shell string
format string
@ -365,8 +366,11 @@ func (w *Writer) writeSegmentColors() {
fg = w.currentForeground
}
// always reset inverted
// w.transparent = false
// ignore processing fully tranparent colors
w.invisible = fg.IsTransparent() && bg.IsTransparent()
if w.invisible {
return
}
if fg.IsTransparent() && len(w.TerminalBackground) != 0 {
background := w.getAnsiFromColorString(w.TerminalBackground, false)
@ -430,6 +434,12 @@ func (w *Writer) writeColorOverrides(match map[string]string, background string,
}
w.currentBackground, w.currentForeground = w.asAnsiColors(match[BG], match[FG])
// ignore processing fully tranparent colors
w.invisible = w.currentForeground.IsTransparent() && w.currentBackground.IsTransparent()
if w.invisible {
return
}
// make sure we have colors
if w.currentForeground.IsEmpty() {
w.currentForeground = w.foreground

View file

@ -10,7 +10,11 @@ import (
)
func (w *Writer) write(i int, s rune) {
// ignore the logic when there is no hyperlink
// ignore processing when invisible (<transparent,transparent>)
if w.invisible {
return
}
// ignore the logic when there is no hyperlink or things arent't visible
if !w.hasHyperlink {
w.length += runewidth.RuneWidth(s)
w.builder.WriteRune(s)