Jaykul / PowerLine

A more PowerShell prompt
MIT License
567 stars 31 forks source link

What is the correct way to write a clear final separator? #69

Open jeremytwfortune opened 1 year ago

jeremytwfortune commented 1 year ago

This code https://github.com/Jaykul/PowerLine/blob/1f5eb7eea692e277d8053c506129496d3a12a828/Source/Public/Write-PowerlinePrompt.ps1#L206-L209

add a final $ColorSeparator to the generated line. This works well when the last prompt has a background color like those displayed in the readme.

However, I like keeping all of my colors up top and print a null background for the last item on the prompt array.

image

I'm explicitly setting $Null colors to allow this.

Set-PowerLinePrompt -Colors $Null, Null

However, if a $ColorSeparator is added on the end, it appears as though the text is rendered with some other background color. This is the effect.

image

I can't seem to find a public way to alter this separator's background color. To achieve the working screenshot I showed above where the background color of the separator is clear, I added a wrapper to check the last background:

if ($Null -ne $LastBackground) {
    $line += ([PoshCode.Pansies.Text]@{
        Object = "$([char]27)[49m$ColorSeparator&Clear;"
        ForegroundColor = $LastBackground
    })
}

which works because the final block sets $LastBackground.

Is there a better, public way to control this last separator?