Skip to content

Instantly share code, notes, and snippets.

@LawrenceHwang
Last active June 8, 2019 18:20
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 LawrenceHwang/b28e20b44eac077f09148782f13ff586 to your computer and use it in GitHub Desktop.
Save LawrenceHwang/b28e20b44eac077f09148782f13ff586 to your computer and use it in GitHub Desktop.
ColourfulProgressBar.ps1
$max = 600
(1..$max).foreach{$x1 = Get-Random -Minimum 0 -Maximum ([math]::ceiling($host.ui.RawUI.WindowSize.Width* ($_/$max))); $x2 = $x1 + 1; $y1 = Get-Random -Minimum 0 -Maximum 1; $y2 = $y1 ;$Host.ui.RawUI.SetBufferContents([System.Management.Automation.Host.Rectangle]::new($x1,$y1,$x2,$y2),([System.Management.Automation.Host.BufferCell]::new([char](Get-Random -Minimum 32 -Maximum 33),([System.ConsoleColor].GetEnumValues() | Get-Random),([System.ConsoleColor].GetEnumValues() | Get-Random),[System.Management.Automation.Host.BufferCellType]::Complete)))}
@jdhitsolutions
Copy link

This didn't do anything unless I cleared the host first. It would also be nicer if you formatted the code as something other than a one-line expression.

@LawrenceHwang
Copy link
Author

Thank you Jeff! Yes this only outputs to the top of existing console buffer and the long line is waaaay less readable. I will make the improvements you mentioned in next revision(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment