Repository navigation
Fix Clear-Host for remote Windows PSSession - #28116
Conversation
Implements the bare minimum on the local PSHostRawUserInterface used on non-Windows to support the `Clear-Host` call when targeting a remote Windows host in `Enter-PSSession`.
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
No unresolved review issues remain.
Review effort: Lite
Findings: None
What changed in this PR
Fixes Clear-Host for remote Windows sessions initiated from non-Windows clients.
Changes:
- Handles the full-buffer clear request.
- Clears the local console with
Console.Clear(). - Preserves unsupported-operation behavior.
| File | Description |
|---|---|
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs |
Implements remote Windows Clear-Host support on Unix clients. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| fill.Character == ' ') | ||
| { | ||
| // Emits the same sequence as the clear command used by the | ||
| // local Clear-Host function. |
There was a problem hiding this comment.
Since this is a workaround for Clear-Host only, I believe we need to explicitly check ForegroundColor and backgroundColor too, as set by Clear-Host.
There was a problem hiding this comment.
The local Clear-Host on non-Windows doesn't check the colors. I think it's fine to ignore the colors here.
There was a problem hiding this comment.
Thanks, I wasn't sure if the actual values set remotely would line up with the ones seen locally which is why I ignored it. I personally think the intent is clear in that setting the position to -1 with the char ' ' is good enough but thank you for confirming.
There was a problem hiding this comment.
$RawUI.SetBufferContents(
@{Top = -1; Bottom = -1; Right = -1; Left = -1},
@{Character = ' '; ForegroundColor = $rawui.ForegroundColor; BackgroundColor = $rawui.BackgroundColor})To catch only such a method call, you need to check the colors too. Otherwise, someone may try to paint over the screen in a different color, and get the screen cleaned, which would mislead users because other parameter values would cause the exception.
…erInterface.cs Co-authored-by: Dongbo Wang <dongbow@microsoft.com>
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
PR Summary
Implements the bare minimum on the local PSHostRawUserInterface used on non-Windows to support the
Clear-Hostcall when targeting a remote Windows host inEnter-PSSession.PR Context
Fixes: #28115
Note: This does not fix
Clear-Hostwhen targeting a non-Windows endpoint, only when targeting a Windows endpoint.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header