From 5b90423e63f213a802b8f9feaa67bc49ddf4ab3b Mon Sep 17 00:00:00 2001 From: Bruce Payette Date: Wed, 6 Jun 2018 23:40:04 -0400 Subject: [PATCH] Fix for #6880 Progress panel displays incorrectly on UNIX when the user is typing. (#6972) This fixes issue #6880 where user input interferes with the way the progress panel is displayed. If the user types any input while running a command displaying progress, that input would be echoed causing the terminal's cursor position to change. On the next progress write, output would be written using the new, incorrect cursor position. This had the effect of causing the progress pane to "march" across the screen if the user held down a key. The fix is fairly simple - update the physical cursor position right before updating the screen. This still leaves a very small window where an individual update might be off by a character or two but this is not cumulative and will be corrected on the next update. I've added code to SetBufferContents() to do this but only on UNIX. It's not a problem on non-VT100 style consoles. --- .../host/msh/ConsoleHostRawUserInterface.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs index 8d90d6af0..af83258cf 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs @@ -1741,7 +1741,6 @@ namespace Microsoft.PowerShell { PSTraceSource.NewArgumentNullException("contents"); } - //if the cursor is on the last line, we need to make more space to print the specified buffer if (origin.Y == BufferSize.Height - 1 && origin.X >= BufferSize.Width) { @@ -1756,6 +1755,14 @@ namespace Microsoft.PowerShell } } +#if UNIX + // Make sure that the physical cursor position matches where we think it is. + // This is a problem on *nix, because input that the user types is echoed + // and that moves the cursor. As a consequence, the cursor needs to be repositioned + // before we update the screen. + CursorPosition = origin; +#endif + //iterate through the buffer to set foreach (var charitem in contents) {