PowerShell window with visible countdown constantly scrolls to bottom its content [UN-SOLVABLE]

Discuss other programming languages besides AutoHotkey
User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

PowerShell window with visible countdown constantly scrolls to bottom its content [UN-SOLVABLE]

05 Aug 2023, 08:04

This OK working PS1 test script

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
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

Code: Select all

$CountdownSeconds = 3
Write-Host "Executing in:"
Write-Host $CountdownSeconds
Write-Host "seconds"
Start-Sleep -Seconds $CountdownSeconds
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?
Last edited by A Keymaker on 09 Dec 2023, 13:06, edited 1 time in total.
User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Re: PowerShell window with visible countdown constantly scrolls to bottom its content

30 Aug 2023, 06:46

A Keymaker wrote:
05 Aug 2023, 08:04
[...]
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?
Well, anyone?
User avatar
A Keymaker
Posts: 455
Joined: 31 May 2022, 13:46
Location: Donjon du Château de Mérovingien

Re: PowerShell window with visible countdown constantly scrolls to bottom its content

09 Dec 2023, 13:04

It seems that currently in the Windows Console [conhost.exe] it is impossible to see digits of a countdown in progress at the bottom of window while also retaining ability to scroll it up an not have the view being thrown back down after passing of yet another second. The new Windows Terminal [windowsterminal.exe] however is supposedly to not snap to the bottom on output if user scrolls up- as it only snaps to the bottom on output if user is already at the bottom of window when it occurs

And so, as Windows Terminal by default replaces the old Windows Terminal since Windows 11 22H2, but installing it on older systems has many prerequisites [https://github.com/Microsoft/Terminal#prerequisites] - thus it is easier to just wait out this issue

[More info: https://github.com/microsoft/terminal/issues/15962]

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 88 guests