Last active
July 13, 2023 00:14
-
-
Save ShaunLawrie/95caba3aeaa51ba83457c422d60ef80f to your computer and use it in GitHub Desktop.
A Basic "Spinner" in PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Do some work | |
Write-Host "Doing some work" | |
$job = Start-Job { | |
Start-Sleep -Seconds 5 | |
} | |
# Spinner | |
$location = $Host.UI.RawUI.CursorPosition | |
$spinnerIcons = @(". ", ".. ", "...") | |
$spinnerIconIndex = 0 | |
[Console]::CursorVisible = $false | |
while($job.State -eq "Running") { | |
[Console]::SetCursorPosition($location.X, $location.Y) | |
Write-Host -ForegroundColor Yellow $spinnerIcons[$spinnerIconIndex] | |
Start-Sleep -Milliseconds 500 | |
$spinnerIconIndex = ($spinnerIconIndex + 1) % $spinnerIcons.Count | |
} | |
[Console]::SetCursorPosition($location.X, $location.Y) | |
[Console]::CursorVisible = $true | |
# Continue work | |
Write-Host "Done" |
Author
ShaunLawrie
commented
May 19, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment