More ANSI Alternatives
I've been demonstrating how to use ANSI to display messages in the console while your PowerShell code is executing. What I've shown you should be considered a proof of concept more than anything. Expect a lot of trial and error to get the desired output. My ideas will work best if your command doesn't write anything to the pipeline, or if it sends output after all of your ANSI-based messaging is complete. But that probably is wishful thinking on my part.
Before we get to today's content, I want to point out a subtle distinction in clearing the console. In the previous article, I mentioned you could use this ANSI sequence to clear the display.
"e[1J"
You may wonder what the difference is between this and using Clear-Host
. It depends on where the cursor is when you clear the screen. If you are at the bottom of the console, using Clear-Host
will scroll the console up, leaving the cursor at the top. Using the ANSI sequence will clear the screen and leave the cursor at the bottom. You can try these two commands to see the difference.