diff --git a/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs b/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs index 1d5ae638e8..3210a8965f 100644 --- a/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs +++ b/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs @@ -72,6 +72,20 @@ namespace Microsoft.PowerShell public class PSConsoleReadlineOptions { +#if CORECLR + public const ConsoleColor DefaultCommentForegroundColor = ConsoleColor.Magenta; + public const ConsoleColor DefaultKeywordForegroundColor = ConsoleColor.Green; + public const ConsoleColor DefaultStringForegroundColor = ConsoleColor.DarkCyan; + public const ConsoleColor DefaultOperatorForegroundColor = ConsoleColor.Gray; + public const ConsoleColor DefaultVariableForegroundColor = ConsoleColor.Green; + public const ConsoleColor DefaultCommandForegroundColor = ConsoleColor.Yellow; + public const ConsoleColor DefaultParameterForegroundColor = ConsoleColor.Green; + public const ConsoleColor DefaultTypeForegroundColor = ConsoleColor.Gray; + public const ConsoleColor DefaultNumberForegroundColor = ConsoleColor.White; + public const ConsoleColor DefaultMemberForegroundColor = ConsoleColor.Gray; + public const ConsoleColor DefaultEmphasisForegroundColor = ConsoleColor.Cyan; + public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red; +#else public const ConsoleColor DefaultCommentForegroundColor = ConsoleColor.DarkGreen; public const ConsoleColor DefaultKeywordForegroundColor = ConsoleColor.Green; public const ConsoleColor DefaultStringForegroundColor = ConsoleColor.DarkCyan; @@ -84,7 +98,7 @@ namespace Microsoft.PowerShell public const ConsoleColor DefaultMemberForegroundColor = ConsoleColor.Gray; public const ConsoleColor DefaultEmphasisForegroundColor = ConsoleColor.Cyan; public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red; - +#endif public const EditMode DefaultEditMode = EditMode.Windows; @@ -166,7 +180,8 @@ namespace Microsoft.PowerShell { HistorySavePath = System.IO.Path.Combine( Environment.GetEnvironmentVariable("HOME"), - ".psreadline", + ".powershell", + "PSReadLine", hostName + "_history.txt"); } #else 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/Keys.cs b/src/Microsoft.PowerShell.PSReadLine/Keys.cs index 5cf1975d67..07166088d6 100644 --- a/src/Microsoft.PowerShell.PSReadLine/Keys.cs +++ b/src/Microsoft.PowerShell.PSReadLine/Keys.cs @@ -3,9 +3,6 @@ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ using System; -#if CORECLR -using System.Runtime.InteropServices; -#endif namespace Microsoft.PowerShell { diff --git a/src/Microsoft.PowerShell.PSReadLine/KillYank.cs b/src/Microsoft.PowerShell.PSReadLine/KillYank.cs index ba94cbdbde..651364c78f 100644 --- a/src/Microsoft.PowerShell.PSReadLine/KillYank.cs +++ b/src/Microsoft.PowerShell.PSReadLine/KillYank.cs @@ -6,7 +6,9 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Management.Automation.Language; -//using System.Windows.Forms; +#if !CORECLR +using System.Windows.Forms; +#endif namespace Microsoft.PowerShell { 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 73be581284..6dd631ee21 100644 --- a/src/Microsoft.PowerShell.PSReadLine/Render.cs +++ b/src/Microsoft.PowerShell.PSReadLine/Render.cs @@ -472,8 +472,14 @@ namespace Microsoft.PowerShell // to invert only the lower 3 bits to change the color is somewhat // but looks best with the 2 default color schemes - starting PowerShell // from it's shortcut or from a cmd shortcut. +#if CORECLR + ConsoleColor tempColor = ((int)foregroundColor == -1) ? ConsoleColor.White : foregroundColor; + foregroundColor = ((int)backgroundColor == -1) ? ConsoleColor.Black : backgroundColor; + backgroundColor = tempColor; +#else foregroundColor = (ConsoleColor)((int)foregroundColor ^ 7); backgroundColor = (ConsoleColor)((int)backgroundColor ^ 7); +#endif } charInfo.ForegroundColor = foregroundColor; @@ -690,6 +696,7 @@ namespace Microsoft.PowerShell #region Screen scrolling +#if !CORECLR /// /// Scroll the display up one screen. /// @@ -808,6 +815,7 @@ namespace Microsoft.PowerShell console.SetWindowPosition(0, newTop); } +#endif #endregion Screen scrolling } } diff --git a/src/Microsoft.PowerShell.PSReadLine/ScreenCapture.cs b/src/Microsoft.PowerShell.PSReadLine/ScreenCapture.cs index be053566a4..2659fec974 100644 --- a/src/Microsoft.PowerShell.PSReadLine/ScreenCapture.cs +++ b/src/Microsoft.PowerShell.PSReadLine/ScreenCapture.cs @@ -19,8 +19,16 @@ namespace Microsoft.PowerShell var buffer = ReadBufferLines(start, count); for (int i = 0; i < buffer.Length; i++) { +#if CORECLR + ConsoleColor tempColor = (int)buffer[i].ForegroundColor == -1 + ? ConsoleColor.White : buffer[i].ForegroundColor; + buffer[i].ForegroundColor = (int)buffer[i].BackgroundColor == -1 + ? ConsoleColor.Black : buffer[i].BackgroundColor; + buffer[i].BackgroundColor = tempColor; +#else buffer[i].ForegroundColor = (ConsoleColor)((int)buffer[i].ForegroundColor ^ 7); buffer[i].BackgroundColor = (ConsoleColor)((int)buffer[i].BackgroundColor ^ 7); +#endif } _singleton._console.WriteBufferLines(buffer, ref start, false); } diff --git a/src/Microsoft.PowerShell.PSReadLine/UndoRedo.cs b/src/Microsoft.PowerShell.PSReadLine/UndoRedo.cs index 128e6548ec..b451231e1a 100644 --- a/src/Microsoft.PowerShell.PSReadLine/UndoRedo.cs +++ b/src/Microsoft.PowerShell.PSReadLine/UndoRedo.cs @@ -76,7 +76,6 @@ namespace Microsoft.PowerShell _singleton.ClearStatusMessage(render: false); } _singleton._edits[_singleton._undoEditIndex - 1].Undo(); - _singleton._edits.RemoveAt(_singleton._undoEditIndex - 1); _singleton._undoEditIndex--; if (_singleton._options.EditMode == EditMode.Vi && _singleton._current >= _singleton._buffer.Length) {