Stopping countdown from scrolling down content of PS window #20472

Open
opened 2026-01-31 07:14:48 +00:00 by claunia · 0 comments
Owner

Originally created by @GitHubinatrix on GitHub (Sep 13, 2023).

I have read these two to discussions

https://github.com/microsoft/terminal/pull/6062

https://github.com/microsoft/terminal/issues/15059

but as I am not a programmer, just a small time script tweaker, can anyone summarize / explain to me these two discussion in more layman terms?

I have this OK working test code

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

10..0 | ForEach-Object {
    [System.Console]::SetCursorPosition(0, $topRow)

    if ($_ -eq 10) {
        Write-Host $_ -NoNewline
    } else {
        Write-Host " $_" -NoNewline
    }

    Start-Sleep -Seconds 1
    Write-Host " `b" -NoNewline
}



# Here will be the main script

Write-Host
Write-Host "Script has been executed"



# Wait for specific user input (ESC, ENTER, or SPACE) before closing the window:

Write-Host "To close this window press either:
Enter
Space
Esc"
Write-Host

do {
    $key = $Host.UI.RawUI.ReadKey('NoEcho, IncludeKeyDown').Character
} while ($key -notin @(' ', [char]13, [char]27))

which stops the PowerShell window at countdown - and after it ends it then proceeds with execution of the rest of the script

But the problem with it that I have is that every appearing digit makes the PS window scroll down its content to the very bottom - thus I can only see what is above this active counter for less than second afterl scrolling up. I can constantly scroll manually but it always goes back to the bottom to show a new digit. I could of course replace that with a silent countdown like this


$CountdownSeconds = 10
Write-Host "Executing in:"
Write-Host $CountdownSeconds
Write-Host "seconds"
Start-Sleep -Seconds $CountdownSeconds

but at a cost of not being informed then about how much time has left

So is there a way to eat a cake and have it - i.e. to see a digits of countdown at the bottom of window but also at any time to be able to scroll up not have the view thrown back down every second?

Originally created by @GitHubinatrix on GitHub (Sep 13, 2023). I have read these two to discussions https://github.com/microsoft/terminal/pull/6062 https://github.com/microsoft/terminal/issues/15059 but as I am not a programmer, just a small time script tweaker, can anyone summarize / explain to me these two discussion in more layman terms? I have this OK working test code ``` 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 10..0 | ForEach-Object { [System.Console]::SetCursorPosition(0, $topRow) if ($_ -eq 10) { Write-Host $_ -NoNewline } else { Write-Host " $_" -NoNewline } Start-Sleep -Seconds 1 Write-Host " `b" -NoNewline } # Here will be the main script Write-Host Write-Host "Script has been executed" # Wait for specific user input (ESC, ENTER, or SPACE) before closing the window: Write-Host "To close this window press either: Enter Space Esc" Write-Host do { $key = $Host.UI.RawUI.ReadKey('NoEcho, IncludeKeyDown').Character } while ($key -notin @(' ', [char]13, [char]27)) ``` which stops the PowerShell window at countdown - and after it ends it then proceeds with execution of the rest of the script But the problem with it that I have is that every appearing digit makes the PS window scroll down its content to the very bottom - thus I can only see what is above this active counter for less than second afterl scrolling up. I can constantly scroll manually but it always goes back to the bottom to show a new digit. I could of course replace that with a silent countdown like this ``` $CountdownSeconds = 10 Write-Host "Executing in:" Write-Host $CountdownSeconds Write-Host "seconds" Start-Sleep -Seconds $CountdownSeconds ``` but at a cost of not being informed then about how much time has left So is there a way to eat a cake and have it - i.e. to see a digits of countdown at the bottom of window but also at any time to be able to scroll up not have the view thrown back down every second?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20472