-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Clear-Host fails to clear the first line #5039
Comments
This is really strange. Would you mind running a quick test for me? Can you do this from Powershell Core outside of Terminal? To reproduce the same conditions as Terminal runs in, you will need to run this first (it will delete and temporarily disable your scrollback, but this is an important part of the repro!) $Host.UI.RawUI.BufferSize = $Host.UI.RawUI.WindowSize |
I performed the following steps (version of coranavirus-tracker-cli on npmjs.com has some issues with upstream API sources, so I pulled latest master):
The problem did not appear when running directly in PowerShell Core, only in Windows Terminal hosted PowerShell Core. |
Yeah, alright, I can definitely reproduce this. Gotta fix for v1. Notes to future debuggers: When I run clear in powershell, this is what I get out of the pty.
Weirdly enough, all those |
|
Alright, this is also doable with some alt buffer trickery. It looks like we're not clearing the top line when [something something scrollback] happens. From PowerShell 7:
Critically, when we redraw (note the missing |
that scroll delta bit scares me |
Okay, nailed it down. This is happening because This concept is invalidated by a full screen scroll-and-redraw. We need to determine whether we're writing to the "new" bottom line before we optimize around its contents already being empty. 😄 Open PR #5181 touches the code that sets |
Moving the cursor clears the |
Okay so #5181 almost fixes this too: Note the one mysterious 'E' immediately following the prompt that's left untouched. If you leave more spaces in the middle of the line, you'll get more 'E's |
Oh my goodness gracious. You wanna know something crazy? This won't repro without PSReadline as well. The trick is that the 'E's will only appear in spaces after the end of one run of text, before the next one starts. PSReadline will color the input as blue-on-default, but pure powershell won't. I've incorporated this into the test I'm building for #5113. |
I’m think that’s less because of PSReadline and more because your top row is fully printed in every column, actually. If you go down one line before running that command, what happens? |
Now that the Terminal is doing a better job of actually marking which lines were and were not wrapped, we're not always copying lines as "wrapped" when they should be. We're more correctly marking lines as not wrapped, when previously we'd leave them marked wrapped. The real problem is here in the `ScrollFrame` method - we'd manually newline the cursor to make the terminal's viewport shift down to a new line. If we had to scroll the viewport for a _wrapped_ line, this would cause the Terminal to mark that line as broken, because conpty would emit an extra `\n` that didn't actually exist. This more correctly implements `ScrollFrame`. Now, well move where we "thought" the cursor was, so when we get to the next `PaintBufferLine`, if the cursor needs to newline for the next line, it'll newline, but if we're in the middle of a wrapped line, we'll just keep printing the wrapped line. A couple follow up bugs were found to be caused by the same bad logic. See #5039 and #5161 for more details on the investigations there. ## References * #4741 RwR, which probably made this worse * #5122, which I branched off of * #1245, #357 - a pair of other conpty wrapped lines bugs * #5228 - A followup issue for this PR ## PR Checklist * [x] Closes #5113 * [x] Closes #5180 (by fixing DECRST 25) * [x] Closes #5039 * [x] Closes #5161 (by ensuring we only `removeSpaces` on the actual bottom line) * [x] I work here * [x] Tests added/passed * [n/a] Requires documentation to be updated ## Validation Steps Performed * Checked the cases from #1245, #357 to validate that they still work * Added more and more tests for these scenarios, and then I added MORE tests * The entire team played with this in selfhost builds
🎉This issue was addressed in #5181, which has now been successfully released as Handy links: |
Environment
Steps to reproduce
corona
to get outputcls
to clear the screenExpected behavior
Screen should be fully cleared.
Actual behavior
The first line retains some characters. This is probably related to the color formatting being used by the CLI. The characters retained are also not from the line that was originally the topmost line.
Output before clearing:
Output after clearing:
Note: A second
cls
finishes clearing the screen.The text was updated successfully, but these errors were encountered: