Stopping countdown from scrolling down content of PS window #20475

Closed
opened 2026-01-31 07:14:55 +00:00 by claunia · 3 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?
Author
Owner

@zadjii-msft commented on GitHub (Sep 20, 2023):

Ah, you're using the vintage console window, conhost.exe, aren't you/?

Here's a great solution! Go try the Windows Terminal instead. In the Terminal, we've updated this to only snap to the bottom on output, if you're already at the bottom. If you scroll up, then we won't snap to the bottom on output.

@zadjii-msft commented on GitHub (Sep 20, 2023): Ah, you're using the vintage console window, `conhost.exe`, aren't you/? Here's a great solution! Go try the Windows Terminal instead. In the Terminal, we've updated this to only snap to the bottom on output, if you're already at the bottom. If you scroll up, then we won't snap to the bottom on output.
Author
Owner

@GitHubinatrix commented on GitHub (Sep 21, 2023):

Thank you for informing me

But because there are many prerequisites for running Windows Terminal on Windows 10 and my time and skills are limited [and I just know, based on my past experiences, that I will stumble on some issues with upgrading my system] thus I think I will just wait out for the time when I will build a new machine with Windows 11 installed on it - as Wikipedia says that is by default replaced with Windows Terminal since Windows 11 22H2

@GitHubinatrix commented on GitHub (Sep 21, 2023): Thank you for informing me But because there are many [prerequisites](https://github.com/Microsoft/Terminal#prerequisites) for running Windows Terminal on Windows 10 and my time and skills are limited [and I just know, based on my past experiences, that I will stumble on some issues with upgrading my system] thus I think I will just wait out for the time when I will build a new machine with Windows 11 installed on it - as [Wikipedia](https://en.wikipedia.org/wiki/Windows_Terminal) says that is by default replaced with Windows Terminal since Windows 11 22H2
Author
Owner

@zadjii-msft commented on GitHub (Sep 21, 2023):

Ah - those are the pre-reqs for building the Terminal locally. If you just want to install it, you can grab it from the Store, or straight off our Releases page.

@zadjii-msft commented on GitHub (Sep 21, 2023): Ah - those are the pre-reqs for building the Terminal locally. If you just want to install it, you can grab it from the Store, or straight off our [Releases page](https://github.com/microsoft/terminal/releases).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20475