All in all I needed to implement an A-OK working solution to my already written multi-step PS1 script that had a purpose of generating a report of what it was doing at a given moment. And the main visual issue kept coming back - which was seeing sometimes the prompt sign still being adjacent to the left edge of window of console for an annoying split of second
And after having wasted hours I can say this: it quickly became a futile game of Whac-A-Mole. Here is in short how it went down:
I thought I was finished when I ended up with two semi-working snippets
Code: Select all
Write-Host "`r" # This clears the line
$A_VARIABLE = @()
# The below modifies the prompt with extra spaces
$THE_PROMPT_SIGN_VISUAL_MODIFICATION = " " * 2 + " " # That separate single white space at the end of this line can be entirely removed or changed into whatever sign or text is desired
Write-Host $THE_PROMPT_SIGN_VISUAL_MODIFICATION -NoNewline
Start-Sleep -Seconds 1 # Timeout for providing a time needed for visual checking of position of the prompt
and
Code: Select all
$CURVLINEAR_COORDINATE = $host.UI.RawUI.CursorPosition # This gets current position of the prompt
# The below moves the position of the prompt relative to the previous one
$host.UI.RawUI.CursorPosition = @{
X = $CURVLINEAR_COORDINATE.X + 3 # Horizontal movement
Y = $CURVLINEAR_COORDINATE.Y # Vertical movement
}
Start-Sleep -Seconds 1 # Timeout for providing a time needed for visual checking of position of the prompt
I decided to use them as a function because there was no observable difference between using the 2 above methods directly and calling them via a function. Only rarely one method seemed to work slightly better than the other in a given segment of the file [i.e. moved the prompt immediately, concealed the prompt, did not interact negatively with the following lines of code] but basically these two yielded the same result. [I also have noticed that some parts of the file containing simpler code made the prompt sign to have apparently to little time to flash itself at all- and thus to flash itself in a wrong position. And adding a timeout there was allowing for the prompt to manifest itself in a possibly wrong position]
But nevertheless I had to polish usage of the above with precisely placed multiple instances of
Code: Select all
[console]::SetCursorPosition(0, [console]::CursorTop - 1)
and / or removal of already existing lines of empty text that were present in my overall code [for upkeeping of the visual design of the report]. And like I said, it was like a game of Whac-A-Mole. The hardest part was adjustment of the dynamic countdown effect
And then as a last resort I introduced into the file the
Code: Select all
[System.Console]::CursorVisible = $false
And as it came to be, such simple turning off the prompt rendered that whole shebang pretty much futile; i.e. it would have been probably a much simpler and quicker to use this command right at the very beginning of code and from the get-go - and then to turn it back on only for desired segments that are visible later on in console, which in turn would allow for having to deal with position of the prompt [also] only in those desired segments of the code [instead of polishing every single segment]
But for now I am keeping usage of my function and all of those on-the-spot adjustments, because removal of them would require another time consuming set of tests needed for restitution of old visuals of lines being drawn in console and addition of new corrections to them. But of course there must be a significant drawback using this miraculous latest polishing method, because Whac-A-Mole is not over: now the countdown looks like it is slowed down by ~100% [i.e. the reported supposed seconds last way too long]
But I will leave it as it is right now