PoshCode Archive  Artifact [35959455c5]

Artifact 35959455c5728938e51167d4b8187f00ba7fd0a165271f95affbde4ef1b8dba5:

  • File Out-Working.ps1 — part of check-in [efd7363636] at 2018-06-10 12:56:19 on branch trunk — Display a “working” animation without knowing how much work you’ll be doing … (user: unknown size: 1229)

# encoding: ascii
# api: powershell
# title: Out-Working
# description: Display a “working” animation without knowing how much work you’ll be doing …
# version: 0.1
# type: script
# license: CC0
# x-poshcode-id: 105
# x-archived: 2008-10-05T09:05:37
#
#
## You'll want to dot-source this into your script
## To change colors, specify the parameters: 
##  . Scripts\OutWorkingScript.ps1 "Yellow" "Blue"
##
## Then you can show progress like this:
##
## $x = 1..50 | out-working 50
##
## Notice that the $wait parameter is only needed if there will not
##  be enough of a delay already (it just slows the loop down)
##

param($fore="White",$back="red")
$work = @( $Host.UI.RawUI.NewBufferCellArray(@("|"),$fore,$back),
           $Host.UI.RawUI.NewBufferCellArray(@("/"),$fore,$back),
           $Host.UI.RawUI.NewBufferCellArray(@("-"),$fore,$back),
           $Host.UI.RawUI.NewBufferCellArray(@("\"),$fore,$back) );

[int]$script:w = 0;

filter out-working($wait=0) {
   $cur = $Host.UI.RawUI.Get_CursorPosition(); 
   $cur.X = 0; $cur.Y -=1;
   $Host.UI.RawUI.SetBufferContents($cur,$work[$script:w++]);
   if($script:w -gt 3) {$script:w = 0 }
   Start-Sleep -milli $wait
   $_
}