In a previous post, I have touched upon the fact that Write-Progress can be quite slow, especially when used in the console host (as opposed to in ISE). So I started to roll my own, with a crucial difference; this progress bar is used inline. This gives it a couple of benefits:
- The progress bar will not disappear after it’s done
- You will keep track of the how far the bar had progressed when an error occurs
- It supports transcripts
On top of that it seems to be quite a lot faster than Write-Progress, according to my tests.
I actually started on this project months ago, got it working but never finished it. Too many other exiting ideas I had to explore I guess. I recently created an animated gif of it in action and put it up on Twitter, and it generated some excitement and people were telling me to release it. That was just the thing to motivate me to finish it. So I did 🙂
Not only that, but I published it on the PowerShell Gallery (must first published module – yay!).
I made the function as similar to Write-Progress as I could, with some added stuff, like the ability to customize the progress bars visuals. To be able to keep it inline, I had to use the PSHost type, and record the cursor position and jumping back a lot. This means that you need to make sure you are not outputting anything to the host inside the loop, or it will break (visually).
I have written some example code of how to use it, and here you can see a screenshot of running that code:
And here are the test code that I used to produce the above:
As I mentioned above, and you probably have noticed from the code examples, I have used transcripts for a couple of the first examples. Here is how the transcript file looks:
A little warning though, there most likely are bugs left in the code, so if you notice any please let me know in the comments sections below. Or even better, help me fix them. The code is on GitHub (https://github.com/gravejester/psInlineProgress).