terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Spaces added to prompt on shell launch (PowerShell/pwsh)

Open yooakim opened this issue 6 years ago • 31 comments

Environment

Win32NT 10.0.19042.0 Microsoft Windows NT 10.0.19042.0
Windows Terminal Version: 1.4.3141.0

https://github.com/justjanne/powerline-go

Steps to reproduce

Add the following to your PowerShell $PROFILE (adjust the path to the powerline-go exectuable to your local environment)

Function global:prompt {
    $pwd = $ExecutionContext.SessionState.Path.CurrentLocation
    $startInfo = New-Object System.Diagnostics.ProcessStartInfo
    $startInfo.FileName = "$ENV:OneDriveConsumer\Util\powerline-go.exe"
    $startInfo.Arguments = "-shell bare"
    $startInfo.Environment["TERM"] = "xterm-256color"
    $startInfo.CreateNoWindow = $true
    $startInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8
    $startInfo.RedirectStandardOutput = $true
    $startInfo.UseShellExecute = $false
    $startInfo.WorkingDirectory = $pwd
    $process = New-Object System.Diagnostics.Process
    $process.StartInfo = $startInfo
    $process.Start() | Out-Null
    $standardOut = $process.StandardOutput.ReadToEnd()
    $process.WaitForExit()
    $standardOut
}

Start a PowerShell (classic) or PowerShell terminal window via Windows Terminal. The first time the prompt function is called there are spaces inserted between the different prompt parts. Pressing Enter makes these disappear and the prompt works fine.

If I use the same profile without Windows Terminal launching PowerShell.exe directly it works fine. So I suspect this is related to Windows Terminal.

Here's an animated GIF that shows what is going on:

powerline-spaces

Expected behavior

I expect to see the prompt formatted correctly as follows: powerline-go-expected

Actual behavior

This is what the prompt looks like when the PowerShell is first started:

powerline-go-actual

yooakim avatar Nov 20 '20 08:11 yooakim

This might sound crazy, but if you highlight that first prompt line, the one with the spaces, then dismiss the selection, does it re-render correctly?

zadjii-msft avatar Nov 20 '20 14:11 zadjii-msft

It looks like you've customized your powershell profile somewhat? I can't reproduce this, but I am not using -NoLogo or have otherwise suppressed the startup banner. 🤔

DHowett avatar Nov 20 '20 17:11 DHowett

Yeah, this only happens with -NoLogo. Interesting!

@zadjii-msft this is coming out of conpty with additional \e[1C in it, but only on the first-ever print to the screen. Everything else comes out fine.

First run

␛[38;5;250m␛[48;5;240m␛[H␣REDMOND\duhowett␛[38;5;240m␛[48;5;238m␛[1C␛[38;5;250m␛[1Cdhowett-sl␛[38;5;238m␛[48;5;31m␛[1C␛[38;5;15m␛[1C~␛[38;5;31m␛[48;5;236m␛[1C␛[38;5;15m␛[1C$␛[38;5;236m␛[49m␛[1C␛[1C␛

After Clear

␛[38;5;250m␛[48;5;240m␣REDMOND\duhowett␣␛[38;5;240m␛[48;5;238m␣␛[38;5;250mdhowett-sl␣␛[38;5;238m␛[48;5;31m␣␛[38;5;15m~␣␛[38;5;31m␛[48;5;236m␣␛[38;5;15m$␣␛[38;5;236m␛[49m␣␛[m

DHowett avatar Nov 20 '20 17:11 DHowett

well that's batty. Thanks for investigating! @DHowett any chance you've got a oneliner repro for me that I can turn into a test? (if not that's cool too, this is probably enough to work off of)

EDIT: J/K read the OP again, that's simple enough. I was worried I had to install a module or something.

zadjii-msft avatar Nov 20 '20 17:11 zadjii-msft

Nah, it's even easier!

test_8341.ps1

"`e[38;5;250m`e[48;5;240m REDMOND\duhowett `e[38;5;240m`e[48;5;238m `e[38;5;250mdhowett-sl `e[38;5;238m`e[48;5;31m `e[38;5;15m~ `e[38;5;31m`e[48;5;236m `e[38;5;15m$ `e[38;5;236m`e[49m `e[m"
sleep 100

wt nt pwsh -c test_8341.ps1

DHowett avatar Nov 20 '20 17:11 DHowett

Just so long as it's the first thing printed to the screen. I used the powershell core escape escape, so it won't work in Windows PowerShell (sorry)

DHowett avatar Nov 20 '20 17:11 DHowett

I've been off-line for a while but thanks for the looking into this :-)

yooakim avatar Dec 03 '20 14:12 yooakim

hmm.. Have the same thing happening to me with Windows terminal Version: 1.4.3243.0 but with Ubuntu wsl after following this guide [https://docs.microsoft.com/sv-se/windows/terminal/tutorials/powerline-setup] . Works fine with wsl.exe.

Resizing the window or open any file and close it will fix the stripes.

ntaken avatar Jan 21 '21 02:01 ntaken

My Windows Terminal was updated yesterday and this started happening for me. Even though I always use up to date versions of everything (or did so until 2 months ago), this never happened before.

Any update on this?

brunovieira97 avatar Sep 11 '21 22:09 brunovieira97

I can confirm that this happens with the -NoLogo option, and only on the first prompt:

image

As a workaround, I've added a cls to my PS profile, which had no impact on launch time:

Import-Module posh-git
Import-Module oh-my-posh
Set-PoshPrompt Paradox
Clear-Host

ghost avatar Sep 12 '21 14:09 ghost

How strange! Would you be willing to try and capture this with the debug tap?

DHowett avatar Sep 13 '21 18:09 DHowett

Wait, I forgot that we already had a repro for this. You can ignore that request!

DHowett avatar Sep 13 '21 18:09 DHowett

@DHowett if you need any assistance in reproducing, or more information on it, count on me! I'm interested in helping in any way I can ;)

brunovieira97 avatar Sep 13 '21 22:09 brunovieira97

ah, I have the same problem. But it perfoms normally before, just becomes like this when I accidentally change the cmd profile. Then my wsl looks like this.

wu-yue-yu avatar Sep 16 '21 04:09 wu-yue-yu

My Windows Terminal was updated yesterday and this started happening for me. Even though I always use up to date versions of everything (or did so until 2 months ago), this never happened before.

Any update on this?

Maybe because of the update? Me too. It jumps out recently.

wu-yue-yu avatar Sep 16 '21 05:09 wu-yue-yu

It happens only start up, and has nothing to do with the logo, I think. image

wu-yue-yu avatar Sep 16 '21 05:09 wu-yue-yu

If there's anything before prompt, it works fine, even print some space before the prompt. image

wu-yue-yu avatar Sep 16 '21 05:09 wu-yue-yu

I am also affected. I'm using Powerline Go https://github.com/justjanne/powerline-go

ayalon avatar Sep 16 '21 12:09 ayalon

Also, when split the window, it will look like this: image

wu-yue-yu avatar Sep 16 '21 14:09 wu-yue-yu

Same issue for me. I'm using powerline-shell in Ubuntu. This issue only occurs in Windows Terminal and not in any other terminal. Including Hyper terminal.

image

This is a fresh install of Windows Terminal and like others it only happens on first render. If I hit enter for a new prompt it renders correctly. The only setting I changed is to set the font to Fira Code which has the separator symbols in it and I set the cursor style to a solid bar. That's it. The rest is all default, though I have toggled plenty of render/appearance settings back and forth to see if anything affected it. No settings seem to affect it.

AlexAllocated avatar Sep 27 '21 02:09 AlexAllocated