diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs index 90893506f..9e11aebf2 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs @@ -1823,9 +1823,13 @@ namespace Microsoft.PowerShell { string input = null; string lastInput = ""; - string lastCompletion = ""; ReadLineResult rlResult = ReadLineResult.endedOnEnter; + +#if !PORTABLE + ConsoleHandle handle = ConsoleControl.GetActiveScreenBufferHandle(); + + string lastCompletion = ""; Size screenBufferSize = RawUI.BufferSize; // Save the cursor position at the end of the prompt string so that we can restore it later to write the @@ -1835,6 +1839,7 @@ namespace Microsoft.PowerShell CommandCompletion commandCompletion = null; string completionInput = null; +#endif do { @@ -1845,9 +1850,6 @@ namespace Microsoft.PowerShell input = ReadLine(true, lastInput, out rlResult, false, false); - Coordinates endOfInputCursorPos = RawUI.CursorPosition; - string completedInput = null; - if (input == null) { break; @@ -1858,6 +1860,13 @@ namespace Microsoft.PowerShell break; } +#if PORTABLE // Portable code only ends on enter (or no input), so tab is not processed + throw new PlatformNotSupportedException("This readline state is unsupported in portable code!"); +#else + + Coordinates endOfInputCursorPos = RawUI.CursorPosition; + string completedInput = null; + if (rlResult == ReadLineResult.endedOnTab || rlResult == ReadLineResult.endedOnShiftTab) { int tabIndex = input.IndexOf(Tab, StringComparison.CurrentCulture); @@ -1946,19 +1955,13 @@ namespace Microsoft.PowerShell if (deltaInput > 0) { - Console.SetCursorPosition(endOfCompletionCursorPos.X, endOfCompletionCursorPos.Y); - for (int i = 0; i < deltaInput; i++) - { - Console.Write(' '); - } + ConsoleControl.FillConsoleOutputCharacter(handle, ' ', deltaInput, endOfCompletionCursorPos); } if (restOfLine != string.Empty) { lastCompletion = completedInput.Remove(completedInput.Length - restOfLine.Length); -#if !PORTABLE SendLeftArrows(restOfLine.Length); -#endif } else { @@ -1967,6 +1970,7 @@ namespace Microsoft.PowerShell lastInput = completedInput; } +#endif } while (true);