10000 correctly presenting progressbar when buffer scrolls and clearing at … · PowerShell/PowerShell@30eb61e · GitHub
[go: up one dir, main page]

Skip to content

Commit 30eb61e

Browse files
SteveL-MSFTlzybkr
authored andcommitted
correctly presenting progressbar when buffer scrolls and clearing at end (#3362)
1 parent bbba61c commit 30eb61e

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

src/Microsoft.PowerShell.ConsoleHost/host/msh/ProgressPane.cs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,32 +91,43 @@ class ProgressPane
9191

9292
int rows = tempProgressRegion.GetLength(0);
9393
int cols = tempProgressRegion.GetLength(1);
94-
_location = _rawui.WindowPosition;
95-
96-
// We have to show the progress pane in the first column, as the screen buffer at any point might contain
97-
// a CJK double-cell characters, which makes it impractical to try to find a position where the pane would
98-
// not slice a character. Column 0 is the only place where we know for sure we can place the pane.
99-
10094
_location.X = 0;
101-
_location.Y = Math.Min(_location.Y + 2, _bufSize.Height);
10295

10396
#if UNIX
104-
// replace the saved region in the screen buffer with our progress display
105-
_location = _rawui.CursorPosition;
97+
_location.Y = _rawui.CursorPosition.Y;
10698

107-
//set the cursor position back to the beginning of the region to overwrite write-progress
108-
//if the cursor is at the bottom, back it up to overwrite the previous write progress
109-
if (_location.Y >= _rawui.BufferSize.Height - rows)
99+
//if the cursor is at the bottom, create screen buffer space by scrolling
100+
int scrollRows = rows - ((_rawui.BufferSize.Height - 1) - _location.Y);
101+
for (int i = 0; i < rows; i++)
110102
{
111103
Console.Out.Write('\n');
112-
if (_location.Y >= rows)
104+
}
105+
if (scrollRows > 0)
106+
{
107+
_location.Y -= scrollRows;
108+
}
109+
110+
//create cleared region to clear progress bar later
111+
_savedRegion = tempProgressRegion;
112+
for(int row = 0; row < rows; row++)
113+
{
114+
for(int col = 0; col < cols; col++)
113115
{
114-
_location.Y -= rows;
116+
_savedRegion[row, col].Character = ' ';
115117
}
116118
}
117119

120+
//put cursor back to where output should be
118121
_rawui.CursorPosition = _location;
119122
#else
123+
_location = _rawui.WindowPosition;
124+
125+
// We have to show the progress pane in the first column, as the screen buffer at any point might contain
126+
// a CJK double-cell characters, which makes it impractical to try to find a position where the pane would
127+
// not slice a character. Column 0 is the only place where we know for sure we can place the pane.
128+
129+
_location.Y = Math.Min(_location.Y + 2, _bufSize.Height);
130+
120131
// Save off the current contents of the screen buffer in the region that we will occupy
121132
_savedRegion =
122133
_rawui.GetBufferContents(

0 commit comments

Comments
 (0)
0