feat(diamond): merge segments on empty leading_diamond

resolves #3623
This commit is contained in:
Jan De Dobbeleer 2023-03-24 21:01:20 +01:00 committed by Jan De Dobbeleer
parent d222ce0211
commit 4ff3bdf359

View file

@ -138,19 +138,18 @@ func (b *Block) RenderSegments() (string, int) {
b.setActiveSegment(segment) b.setActiveSegment(segment)
b.renderActiveSegment() b.renderActiveSegment()
} }
b.writePowerline(true) b.writeSeparator(true)
return b.writer.String() return b.writer.String()
} }
func (b *Block) renderActiveSegment() { func (b *Block) renderActiveSegment() {
b.writePowerline(false) b.writeSeparator(false)
switch b.activeSegment.style() { switch b.activeSegment.style() {
case Plain, Powerline: case Plain, Powerline:
b.writer.Write(ansi.Background, ansi.Foreground, b.activeSegment.text) b.writer.Write(ansi.Background, ansi.Foreground, b.activeSegment.text)
case Diamond: case Diamond:
b.writer.Write(ansi.Transparent, ansi.Background, b.activeSegment.LeadingDiamond) b.writer.Write(ansi.Transparent, ansi.Background, b.activeSegment.LeadingDiamond)
b.writer.Write(ansi.Background, ansi.Foreground, b.activeSegment.text) b.writer.Write(ansi.Background, ansi.Foreground, b.activeSegment.text)
b.writer.Write(ansi.Transparent, ansi.Background, b.activeSegment.TrailingDiamond)
case Accordion: case Accordion:
if b.activeSegment.Enabled { if b.activeSegment.Enabled {
b.writer.Write(ansi.Background, ansi.Foreground, b.activeSegment.text) b.writer.Write(ansi.Background, ansi.Foreground, b.activeSegment.text)
@ -160,7 +159,21 @@ func (b *Block) renderActiveSegment() {
b.writer.SetParentColors(b.previousActiveSegment.background(), b.previousActiveSegment.foreground()) b.writer.SetParentColors(b.previousActiveSegment.background(), b.previousActiveSegment.foreground())
} }
func (b *Block) writePowerline(final bool) { func (b *Block) writeSeparator(final bool) {
isCurrentDiamond := b.activeSegment.style() == Diamond
if final && isCurrentDiamond {
b.writer.Write(ansi.Transparent, ansi.Background, b.activeSegment.TrailingDiamond)
return
}
isPreviousDiamond := b.previousActiveSegment != nil && b.previousActiveSegment.style() == Diamond
if isPreviousDiamond && isCurrentDiamond && len(b.activeSegment.LeadingDiamond) == 0 {
b.writer.Write(ansi.Background, ansi.ParentBackground, b.previousActiveSegment.TrailingDiamond)
return
}
if isPreviousDiamond && len(b.previousActiveSegment.TrailingDiamond) > 0 {
b.writer.Write(ansi.Transparent, ansi.ParentBackground, b.previousActiveSegment.TrailingDiamond)
}
resolvePowerlineSymbol := func() string { resolvePowerlineSymbol := func() string {
var symbol string var symbol string
if b.activeSegment.isPowerline() { if b.activeSegment.isPowerline() {