From f254ea1cdd53b55a574932f344c8a4f2dd93ccba Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL)" Date: Tue, 8 Jan 2019 15:08:53 -0800 Subject: [PATCH] change clear-host back to using $RAWUI and `clear` to work over remoting --- .../engine/InitialSessionState.cs | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index fc4bbb303b2..a2081e04721 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -4069,12 +4069,30 @@ internal void ImportCmdletsFromAssembly(Assembly assembly, PSModuleInfo module) /// internal static string GetClearHostFunctionText() { - return @" -[Console]::Clear() + 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 "; + } + else + { + // Porting note: non-Windows platforms use `clear` + return @" +& (Get-Command -CommandType Application clear | Select-Object -First 1).Definition +# .Link +# https://go.microsoft.com/fwlink/?LinkID=225747 +# .ExternalHelp System.Management.Automation.dll-help.xml +"; + } } ///