Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yooakim opened this issue Nov 20, 2020 · 31 comments · Fixed by #13665
Closed

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

yooakim opened this issue Nov 20, 2020 · 31 comments · Fixed by #13665
Assignees
Labels
Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-3 A description (P3) Product-Conpty For console issues specifically related to conpty Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@yooakim
Copy link

yooakim commented Nov 20, 2020

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

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Nov 20, 2020
@zadjii-msft
Copy link
Member

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 zadjii-msft added Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something Product-Terminal The new Windows Terminal. labels Nov 20, 2020
@DHowett
Copy link
Member

DHowett commented Nov 20, 2020

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
Copy link
Member

DHowett commented Nov 20, 2020

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 DHowett added Product-Conpty For console issues specifically related to conpty and removed Product-Terminal The new Windows Terminal. labels Nov 20, 2020
@zadjii-msft
Copy link
Member

zadjii-msft commented Nov 20, 2020

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 zadjii-msft added Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-3 A description (P3) and removed Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something labels Nov 20, 2020
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Nov 20, 2020
@zadjii-msft zadjii-msft added this to the Terminal v2.0 milestone Nov 20, 2020
@zadjii-msft zadjii-msft removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Nov 20, 2020
@DHowett
Copy link
Member

DHowett commented Nov 20, 2020

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
Copy link
Member

DHowett commented Nov 20, 2020

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)

@yooakim
Copy link
Author

yooakim commented Dec 3, 2020

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

@ntaken
Copy link

ntaken commented Jan 21, 2021

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.

@brunovieira97
Copy link

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?

@ghost
Copy link

ghost commented Sep 12, 2021

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

@DHowett
Copy link
Member

DHowett commented Sep 13, 2021

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

@DHowett
Copy link
Member

DHowett commented Sep 13, 2021

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

@brunovieira97
Copy link

@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 ;)

@wu-yue-yu
Copy link

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
Copy link

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.

@zadjii-msft zadjii-msft added this to the Terminal v1.14 milestone Jan 31, 2022
@DHowett
Copy link
Member

DHowett commented Feb 1, 2022

HA! We finally have a root cause for this. I ran into a different issue, where the "version update" notification was losing the background color around the edges, and it all started to fall into place.

image

If we are painting the first frame or any frame after you clear the entire screen, as an optimization[^1] we don't send a bunch of space characters. We neglected to check whether those space characters were meaningful (had background colors, underlines, other attributes...). This happens for each run of text (so, region of text bordered by a color/attribute change), not per line.

Proximal area of failure:

// If we're not using erase char, but we did erase all at the start of the
// frame, don't add spaces at the end.
//
// GH#5161: Only removeSpaces when we're in the _newBottomLine state and the
// line we're trying to print right now _actually is the bottom line_
//
// GH#5291: DON'T remove spaces when the row wrapped. We might need those
// spaces to preserve the wrap state of this line, or the cursor position.
// For example, vim.exe uses "~ "... to clear the line, and then leaves
// the lines _wrapped_. It doesn't care to manually break the lines, but if
// we trimmed the spaces off here, we'd print all the "~"s one after another
// on the same line.
const bool removeSpaces = !lineWrapped && (useEraseChar ||
_clearedAllThisFrame ||
(_newBottomLine && printingBottomLine && bgMatched));

I wonder if we can use this function to help:

// This returns whether this attribute, if printed directly next to another attribute, for the space
// character, would look identical to the other one.
bool HasIdenticalVisualRepresentationForBlankSpace(const TextAttribute& other, const bool inverted = false) const noexcept

[^1] The ConPTY API tries very hard to pretend that it is not translating a buffer of 120x30 cells into VT . . . so it lies, cheats and steals sometimes. The buffer contains 3900 empty spaces on startup, so we try not to send them to apps.

@DHowett
Copy link
Member

DHowett commented Feb 17, 2022

image

It's testable!
I am not certain the right way to fix it, but it's fixable too. The test passes as of c9e2069, but the attribute math is not correct (to which I suspect @j4james will attest)

@DHowett DHowett self-assigned this Feb 17, 2022
@zadjii-msft zadjii-msft added the zInbox-Bug Ignore me! label Mar 10, 2022
@zadjii-msft zadjii-msft removed the zInbox-Bug Ignore me! label Mar 24, 2022
@zadjii-msft zadjii-msft modified the milestones: Terminal v1.14, 22H2 Apr 28, 2022
@ghost ghost added the In-PR This issue has a related PR label Aug 3, 2022
@ghost ghost closed this as completed in #13665 Aug 8, 2022
@ghost ghost added Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels Aug 8, 2022
ghost pushed a commit that referenced this issue Aug 8, 2022
This bug arose from a "race condition" in the first frame handling of conpty. We'd try to optimize out spaces if we've cleared the entire frame (which always happens on the first frame). However, doing that even for colored spaces meant that things like powerline prompts could be emitted to conhost during the first frame, and we'd optimize the spaces out. That's silly. 

This is hard to repro naturally, but this comment has another repro I used
#8341 (comment)

Modified to facilitate simpler testing, it looks like:

#### Before
![image](https://user-images.githubusercontent.com/18356694/182680119-bb22179c-a328-43f3-b64a-0d1d5773b813.png)

#### After
![image](https://user-images.githubusercontent.com/18356694/182680159-805964c5-c4cc-411a-8865-3866fca8d6e9.png)


* [x] Closes #8341
* [x] Tests added

Co-authored by @DHowett
DHowett pushed a commit that referenced this issue Aug 8, 2022
This bug arose from a "race condition" in the first frame handling of conpty. We'd try to optimize out spaces if we've cleared the entire frame (which always happens on the first frame). However, doing that even for colored spaces meant that things like powerline prompts could be emitted to conhost during the first frame, and we'd optimize the spaces out. That's silly.

This is hard to repro naturally, but this comment has another repro I used
#8341 (comment)

Modified to facilitate simpler testing, it looks like:

#### Before
![image](https://user-images.githubusercontent.com/18356694/182680119-bb22179c-a328-43f3-b64a-0d1d5773b813.png)

#### After
![image](https://user-images.githubusercontent.com/18356694/182680159-805964c5-c4cc-411a-8865-3866fca8d6e9.png)

* [x] Closes #8341
* [x] Tests added

Co-authored by @DHowett

(cherry picked from commit 210a98e)
Service-Card-Id: 84836597
Service-Version: 1.15
@ghost
Copy link

ghost commented Aug 17, 2022

🎉This issue was addressed in #13665, which has now been successfully released as Windows Terminal v1.14.228.:tada:

Handy links:

@ghost
Copy link

ghost commented Aug 17, 2022

🎉This issue was addressed in #13665, which has now been successfully released as Windows Terminal Preview v1.15.228.:tada:

Handy links:

PKRoma pushed a commit to PKRoma/Terminal that referenced this issue Oct 15, 2022
…soft#13665)

This bug arose from a "race condition" in the first frame handling of conpty. We'd try to optimize out spaces if we've cleared the entire frame (which always happens on the first frame). However, doing that even for colored spaces meant that things like powerline prompts could be emitted to conhost during the first frame, and we'd optimize the spaces out. That's silly.

This is hard to repro naturally, but this comment has another repro I used
microsoft#8341 (comment)

Modified to facilitate simpler testing, it looks like:

![image](https://user-images.githubusercontent.com/18356694/182680119-bb22179c-a328-43f3-b64a-0d1d5773b813.png)

![image](https://user-images.githubusercontent.com/18356694/182680159-805964c5-c4cc-411a-8865-3866fca8d6e9.png)

* [x] Closes microsoft#8341
* [x] Tests added

Co-authored by @DHowett

(cherry picked from commit 210a98e)
Service-Card-Id: 84836596
Service-Version: 1.14
@Un1q32
Copy link

Un1q32 commented Dec 1, 2022

i seem to have a similar issue
Screenshot (4) edit

It's different on different font sizes. The above screenshot is with a font size of 12, but with a font size of 13 the gaps disappear.

@zadjii-msft
Copy link
Member

@OldWorldOrdr Nah, that's more like, well, one of these: https://github.com/microsoft/terminal/issues?q=is%3Aissue+is%3Aopen+line+drawing

There's a few of those, so it's hard to point the finger at just one.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Rendering Text rendering, emoji, complex glyph & font-fallback issues Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-3 A description (P3) Product-Conpty For console issues specifically related to conpty Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.