Skip to content

Instantly share code, notes, and snippets.

@CosmosKey
Created August 26, 2017 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CosmosKey/7db6184122b861e67f05a2522587f2ac to your computer and use it in GitHub Desktop.
Save CosmosKey/7db6184122b861e67f05a2522587f2ac to your computer and use it in GitHub Desktop.
Console Cursor Lab, handling cursors in [console]
Write-Host "Done Name State HasData"
$global:js = [System.Collections.ArrayList]::new()
for($i=0;$i -lt 10;$i++){
$j = Start-Job {"JOB" + $using:i;Start-Sleep -Milliseconds (Get-Random -Maximum 3000 -Minimum 0) } -Name "MyJob-$i"
$j | Add-Member -Name CursorTop -MemberType NoteProperty -Value ([console]::CursorTop) -Force
[void]$js.Add($j)
Write-Host "x " -ForegroundColor Red -NoNewline
Write-Host ("{0} {1} {2}" -f $j.Name,$j.State,$j.HasMoreData)
}
[console]::CursorVisible = $false
function SetColor {
$js | ? state -eq Completed | % {
$l = [console]::CursorLeft
$t = [console]::CursorTop
$fg = [console]::ForegroundColor
[console]::SetCursorPosition(0,$_.CursorTop)
[console]::ForegroundColor = "green"
[console]::Write("x")
[console]::ForegroundColor = $fg
[console]::SetCursorPosition($l,$t)
}
}
while(($js | ? state -eq Completed).count -ne $js.count) {
SetColor $js
}
SetColor $js
$js | Remove-Job
[console]::CursorVisible = $true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment