PowerShell window with visible countdown constantly scrolls to bottom its content [UN-SOLVABLE]
Posted: 05 Aug 2023, 08:04
This OK working PS1 test script
displays so many lines that it exceeds vertical size of my screen. After showing them it halts at a visually pleasing countdown- and when the time end it proceeds with execution of its remaining part [which is irrelevant here]
But the problem with it is that with each new digit the PowerShell window scrolls down its content to its bottom - thus I can see only for a single second what is above this changing counter. Of course I can constantly scroll up manually but nevertheless it will always go back to the bottom fr the purpose of showing a new digit. I could instead of it use a silent countdown like this
but if I do then I will not be informed of how much time has left
So is there a way to eat a PS1 cake and have it; i.e. to see a dynamic countdown at the bottom of PowerShell window but also at any time have the ability to scroll up within it without having focus in it thrown down every second?
Code: Select all
# Text to be read by user:
Write-Host "Line of text at the very top"
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host "Line of text in the middle"
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host "Last line of text"
Write-Host "Executing in:"
Write-Host
# Countdown:
$topRow = [System.Console]::CursorTop
3..0 | ForEach-Object {
[System.Console]::SetCursorPosition(0, $topRow)
if ($_ -eq 3) { # Showcase of the first digit / second
Write-Host
Write-Host
Write-Host " Executing deletion in"
Write-Host
Write-Host " ► $_ ◄"
Write-Host " "
Write-Host " seconds"
Write-Host
} else { # Showcase of the remaining digits / seconds
Write-Host
Write-Host
Write-Host " Executing deletion in"
Write-Host
Write-Host " ► $_ ◄"
Write-Host " "
Write-Host " seconds"
Write-Host
}
Start-Sleep -Seconds 1
Write-Host " `b"
}
# Here will be the main script
# Post execution message
Write-Host
Write-Host "Script has been executed"
Read-Host
But the problem with it is that with each new digit the PowerShell window scrolls down its content to its bottom - thus I can see only for a single second what is above this changing counter. Of course I can constantly scroll up manually but nevertheless it will always go back to the bottom fr the purpose of showing a new digit. I could instead of it use a silent countdown like this
Code: Select all
$CountdownSeconds = 3
Write-Host "Executing in:"
Write-Host $CountdownSeconds
Write-Host "seconds"
Start-Sleep -Seconds $CountdownSeconds
So is there a way to eat a PS1 cake and have it; i.e. to see a dynamic countdown at the bottom of PowerShell window but also at any time have the ability to scroll up within it without having focus in it thrown down every second?