From 2cfe3d57a698bb82d9cde41aa6c1915c63a41879 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Fri, 31 Mar 2017 11:38:01 -0700 Subject: [PATCH] Fix progress bar display when cursor not at left edge Fix by saving the cursor position, displaying the progress, and restoring the cursor back to the original position so normal formatting (e.g. table output) can continue. Closes #3453. --- .../host/msh/ProgressPane.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs index 7737d4203c..e9b0ed1d69 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs @@ -91,11 +91,20 @@ namespace Microsoft.PowerShell int rows = tempProgressRegion.GetLength(0); int cols = tempProgressRegion.GetLength(1); + + _savedCursor = _rawui.CursorPosition; _location.X = 0; #if UNIX _location.Y = _rawui.CursorPosition.Y; + // if cursor is not on left edge already move down one line + if (_rawui.CursorPosition.X != 0) + { + _location.Y++; + _rawui.CursorPosition = _location; + } + //if the cursor is at the bottom, create screen buffer space by scrolling int scrollRows = rows - ((_rawui.BufferSize.Height - 1) - _location.Y); for (int i = 0; i < rows; i++) @@ -105,6 +114,7 @@ namespace Microsoft.PowerShell if (scrollRows > 0) { _location.Y -= scrollRows; + _savedCursor.Y -= scrollRows; } //create cleared region to clear progress bar later @@ -161,6 +171,7 @@ namespace Microsoft.PowerShell _rawui.SetBufferContents(_location, _savedRegion); _savedRegion = null; + _rawui.CursorPosition = _savedCursor; } } @@ -249,6 +260,7 @@ namespace Microsoft.PowerShell private Coordinates _location = new Coordinates(0, 0); + private Coordinates _savedCursor; private Size _bufSize; private BufferCell[,] _savedRegion; private BufferCell[,] _progressRegion;