From 74b5060f6efcc5585a90791d6a5b1407f92ef8c3 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Thu, 28 Apr 2016 16:05:00 -0700 Subject: [PATCH] Fix ClearScreen, and disable scroll-related functions that don't work in CoreCLR --- src/Microsoft.PowerShell.PSReadLine/ConsoleLib.cs | 7 +++++++ src/Microsoft.PowerShell.PSReadLine/KeyBindings.cs | 4 +++- src/Microsoft.PowerShell.PSReadLine/Movement.cs | 6 ++++++ src/Microsoft.PowerShell.PSReadLine/PublicAPI.cs | 3 +++ src/Microsoft.PowerShell.PSReadLine/Render.cs | 2 ++ 5 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.PSReadLine/ConsoleLib.cs b/src/Microsoft.PowerShell.PSReadLine/ConsoleLib.cs index 27bbd374f3..deadf12e37 100644 --- a/src/Microsoft.PowerShell.PSReadLine/ConsoleLib.cs +++ b/src/Microsoft.PowerShell.PSReadLine/ConsoleLib.cs @@ -908,6 +908,13 @@ namespace Microsoft.PowerShell.Internal NativeMethods.ReleaseDC(_hwnd, _hDC); } } + +#if CORECLR + public void Clear() + { + Console.Clear(); + } +#endif } #pragma warning restore 1591 diff --git a/src/Microsoft.PowerShell.PSReadLine/KeyBindings.cs b/src/Microsoft.PowerShell.PSReadLine/KeyBindings.cs index 8fff509483..207f5cae15 100644 --- a/src/Microsoft.PowerShell.PSReadLine/KeyBindings.cs +++ b/src/Microsoft.PowerShell.PSReadLine/KeyBindings.cs @@ -181,10 +181,12 @@ namespace Microsoft.PowerShell { Keys.ShiftF3, MakeKeyHandler(CharacterSearchBackward, "CharacterSearchBackward") }, { Keys.F8, MakeKeyHandler(HistorySearchBackward, "HistorySearchBackward") }, { Keys.ShiftF8, MakeKeyHandler(HistorySearchForward, "HistorySearchForward") }, +#if !CORECLR { Keys.PageUp, MakeKeyHandler(ScrollDisplayUp, "ScrollDisplayUp") }, { Keys.PageDown, MakeKeyHandler(ScrollDisplayDown, "ScrollDisplayDown") }, { Keys.CtrlPageUp, MakeKeyHandler(ScrollDisplayUpLine, "ScrollDisplayUpLine") }, { Keys.CtrlPageDown, MakeKeyHandler(ScrollDisplayDownLine, "ScrollDisplayDownLine") }, +#endif }; _chordDispatchTable = new Dictionary>(); @@ -267,13 +269,13 @@ namespace Microsoft.PowerShell { Keys.VolumeDown, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeUp, MakeKeyHandler(Ignore, "Ignore") }, { Keys.VolumeMute, MakeKeyHandler(Ignore, "Ignore") }, -#endif { Keys.PageUp, MakeKeyHandler(ScrollDisplayUp, "ScrollDisplayUp") }, { Keys.CtrlPageUp, MakeKeyHandler(ScrollDisplayUpLine, "ScrollDisplayUpLine") }, { Keys.PageDown, MakeKeyHandler(ScrollDisplayDown, "ScrollDisplayDown") }, { Keys.CtrlPageDown, MakeKeyHandler(ScrollDisplayDownLine,"ScrollDisplayDownLine") }, { Keys.CtrlHome, MakeKeyHandler(ScrollDisplayTop, "ScrollDisplayTop") }, { Keys.CtrlEnd, MakeKeyHandler(ScrollDisplayToCursor,"ScrollDisplayToCursor") }, +#endif }; _chordDispatchTable = new Dictionary>(); diff --git a/src/Microsoft.PowerShell.PSReadLine/Movement.cs b/src/Microsoft.PowerShell.PSReadLine/Movement.cs index f7d7b74ad4..610ee04628 100644 --- a/src/Microsoft.PowerShell.PSReadLine/Movement.cs +++ b/src/Microsoft.PowerShell.PSReadLine/Movement.cs @@ -434,6 +434,11 @@ namespace Microsoft.PowerShell public static void ClearScreen(ConsoleKeyInfo? key = null, object arg = null) { var console = _singleton._console; +#if CORECLR + console.Clear(); + _singleton._initialY = 0; + _singleton.Render(); +#else if (_singleton._initialY + console.WindowHeight > console.BufferHeight) { var scrollCount = _singleton._initialY - console.WindowTop; @@ -445,6 +450,7 @@ namespace Microsoft.PowerShell { console.SetWindowPosition(0, _singleton._initialY); } +#endif } // Try to convert the arg to a char, return 0 for failure diff --git a/src/Microsoft.PowerShell.PSReadLine/PublicAPI.cs b/src/Microsoft.PowerShell.PSReadLine/PublicAPI.cs index f245ec49a4..8f38d5bf1e 100644 --- a/src/Microsoft.PowerShell.PSReadLine/PublicAPI.cs +++ b/src/Microsoft.PowerShell.PSReadLine/PublicAPI.cs @@ -54,6 +54,9 @@ namespace Microsoft.PowerShell void StartRender(); int LengthInBufferCells(char c); void EndRender(); +#if CORECLR + void Clear(); +#endif } #pragma warning restore 1591 diff --git a/src/Microsoft.PowerShell.PSReadLine/Render.cs b/src/Microsoft.PowerShell.PSReadLine/Render.cs index fb7cec8076..6dd631ee21 100644 --- a/src/Microsoft.PowerShell.PSReadLine/Render.cs +++ b/src/Microsoft.PowerShell.PSReadLine/Render.cs @@ -696,6 +696,7 @@ namespace Microsoft.PowerShell #region Screen scrolling +#if !CORECLR /// /// Scroll the display up one screen. /// @@ -814,6 +815,7 @@ namespace Microsoft.PowerShell console.SetWindowPosition(0, newTop); } +#endif #endregion Screen scrolling } }