Created
August 26, 2017 10:18
-
-
Save CosmosKey/7db6184122b861e67f05a2522587f2ac to your computer and use it in GitHub Desktop.
Console Cursor Lab, handling cursors in [console]
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
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