Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I verified this bug on my own machine. As soon as you start wrapping the buffer, -nonewline fails to live up to its task.</p> <p>You can do a few things as a workaround:</p> <p>1) Programmatically increase the BufferSize to a fixed size</p> <pre><code>$Host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(120, 5000) </code></pre> <p>2) Clear the screen every so often, perhaps every 100 nodes or after each node if you don't need to follow the output</p> <p>3) Clear the screen only when you've nearly reached the buffer limit</p> <pre><code>if($Host.UI.RawUI.CursorPosition.Y -gt ($Host.UI.RawUI.BufferSize.Height - 5)) {cls} </code></pre> <p>4) Clear only old parts of the screen buffer by temporarily reducing the size of the buffer. I used your function, untouched (except renaming to remove the second "-"). With the screen buffer at 100, the odd behavior would start at number 50 (2 output lines per loop)</p> <pre><code>49 / 2000 [####################] 100% | FINAL 50 / 2000 [#### ] 20% | First [######## ] 40% | Second [############ ] 60% | Third [################ ] 80% | Fourth [####################] 100% | FINAL 51 / 2000 [#### ] 20% | First [######## ] 40% | Second [############ ] 60% | Third [################ ] 80% | Fourth [####################] 100% | FINAL </code></pre> <p>But with the BufferSize switching, I made it all the way to 2000/2000 without a hitch </p> <pre><code>1998 / 2000 [####################] 100% | FINAL 1999 / 2000 [####################] 100% | FINAL 2000 / 2000 [####################] 100% | FINAL $range = 1..2000 </code></pre> <p>Test code below:</p> <pre><code>foreach($i in $range) { $Host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(120, 3000) Write-Host Write-Host $i "/ 2000" Update-ProgressBar "20" "First" Update-ProgressBar "40" "Second" Update-ProgressBar "60" "Third" Update-ProgressBar "80" "Fourth" Update-ProgressBar "100" "FINAL" $Host.UI.RawUI.BufferSize = New-Object System.Management.Automation.Host.Size(120, 2990) } </code></pre> <p>Realistically, you could combine 3 and 4 so that you only clear the old parts of the buffer when it is nearly full.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload