-
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 does not clear the previous content (Powershell) #3126
Comments
Same thing with WSL, where |
Just checked: this will almost certainly be fixed by /dup #2715. If PowerShell is clearing the screen in another way (which it might be doing), we'll have to evaluate then. PowerShell Core, however, can always be updated to take advantage of CSI 3 J |
Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report! |
We're going to need to look at this again. We're going to pass through We probably need to consider and engage on fixing those. |
I'm pulling the triage tag and putting this in v1.0: this is a complaint we receive so often that we'd be remiss to ship a final product without giving it an investigation. |
It looks like both CMD and PowerShell...
PowerShell further..
This might(?) be detectable. |
Discussion from triage room: we can probably quirk it for cmd and powershell (powershell and pwsh.exe). |
This issue was very common in VsCode/PowerShell. But they managed to fix it. Here's a PR: PowerShell/vscode-powershell#2316 Maybe it can be easily ported. |
No, they did a workaround that is specific to that project and VS Code. It can't even be ported to other PowerShell Editor Service Clients. They run a custom console so they changed the clear command to run a VS Code command. The regular PowerShell and CMD consoles do not clear in VS Code. |
Self notes from what Dustin commented months ago during triage: PowerShellPowershell clears the screen with: if (Platform.IsWindows)
{
// use $RawUI so this works over remoting where there isn't a physical console
return @"
$RawUI = $Host.UI.RawUI
$RawUI.CursorPosition = @{X=0;Y=0}
$RawUI.SetBufferContents(
@{Top = -1; Bottom = -1; Right = -1; Left = -1},
@{Character = ' '; ForegroundColor = $rawui.ForegroundColor; BackgroundColor = $rawui.BackgroundColor})
# .Link
# https://go.microsoft.com/fwlink/?LinkID=225747
# .ExternalHelp System.Management.Automation.dll-help.xml
";
} Which then calls to: if (region.Left == -1 && region.Right == -1 && region.Top == -1 && region.Bottom == -1)
{
if (bufferWidth % 2 == 1 &&
ConsoleControl.IsCJKOutputCodePage(out codePage) &&
LengthInBufferCells(fill.Character) == 2)
{
throw PSTraceSource.NewArgumentException("fill");
}
int cells = bufferWidth * bufferHeight;
ConsoleControl.FillConsoleOutputCharacter(handle, fill.Character, cells, origin);
ConsoleControl.FillConsoleOutputAttribute(handle, attribute, cells, origin);
return;
} CMDCMD on the other hand calls ScrollConsoleScreenBuffer( handle, { 0, 0, bufferWidth, bufferHeight }, nullptr, { 0, -bufferHeight }, {space with the current attributes});
SetConsoleCursorPosition( handle, {0, 0} ); (more or less) |
## Summary of the Pull Request This PR implements a pair of shims for `cmd` and `powershell`, so that their `cls` and `Clear-Host` functions will clear the entire terminal buffer (like they do in conhost), instead of just the viewport. With the conpty viewport and buffer being the same size, there's effectively no way to know if an application is calling these API's in this way with the intention of clearing the buffer or the viewport. We absolutely have to guess. Each of these shims checks to see if the way that the API is being called exactly matches the way `cmd` or `powershell` would call these APIs. If it does, we manually write a `^[[3J` to the connected terminal, to get he Terminal to clear it's own scrollback. ~~_⚠️ If another application were trying to clear the **viewport** with an exactly similar API call, this would also cause the terminal scrollback to get cleared⚠️ _~~ * [x] Should these shims be restricted to when the process that's calling them is actually `cmd.exe` or `powershell.exe`? Can I even do this? I think we've done such a good job of isolating the client process information from the rest of the host code that I can't figure out how to do this. - YES, this can be done, and I did it. * [ ] **TODO**: _While I'm here_, should I have `DoSrvPrivateEraseAll` (the implementation for `^[[2J`, in `getset.cpp`) also manually trigger a EraseAll in the terminal in conpty mode? ## PR Checklist * [x] Closes #3126 * [x] Actually closes #1305 too, which is really the same thing, but probably deserves a callout * [x] I work here * [x] Tests added/passed * [n/a] Requires documentation to be updated ## Validation Steps Performed * ran tests * checked `cls` in the Terminal * checked `Clear-Host` in the Terminal * Checked running `powershell clear-host` from `cmd.exe`
🎉This issue was addressed in #5627, which has now been successfully released as Handy links: |
Environment
Steps to reproduce
Expected behavior
Cannot scroll up,
Clear-Host
cleared the terminal, all previous output is gone.Actual behavior
Scrolling up shows previous output. This repros with both Powershel 6.2.3 and 5.2.1.
This does not happen with the powershell terminal, which correctly removes all previous output.
The text was updated successfully, but these errors were encountered: