Skip to content

Instantly share code, notes, and snippets.

@Noxsios
Created July 25, 2021 20:20
Show Gist options
  • Save Noxsios/1f93dfb4f7c67c5f94cc8caeec2d537e to your computer and use it in GitHub Desktop.
Save Noxsios/1f93dfb4f7c67c5f94cc8caeec2d537e to your computer and use it in GitHub Desktop.
Fancy typewriter function to add flair to Write-Host
function Write-Typewriter {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline)]
[string]$Text,
[Parameter()]
[ConsoleColor]$Color = [ConsoleColor]::Green,
[Parameter()]
[int]$Delay = 200,
[Parameter()]
[Switch]$Rainbow = $false,
[Parameter()]
[Switch]$Pause = $false
)
begin {
$r = New-Object System.Random
$color_count = [System.ConsoleColor].GetFields().Count - 1
}
process {
$Text -split "" | ForEach-Object {
if ($Rainbow) {
$r_color = [System.ConsoleColor](Get-Random -Min 0 -Max $color_count)
Write-Host $_ -NoNewline -ForegroundColor $r_color
}
else {
Write-Host $_ -NoNewline -ForegroundColor $Color
}
Start-Sleep -Milliseconds $(1 + $r.Next($Delay))
}
}
end {
Write-Host "`r`n"
if ($Pause) {
Pause
}
}
}
Set-Alias -Name "wtw" -Value Write-Typewriter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment