-
-
Notifications
You must be signed in to change notification settings - Fork 428
/
write-animated.ps1
executable file
·40 lines (37 loc) · 1.1 KB
/
write-animated.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<#
.SYNOPSIS
Writes animated text
.DESCRIPTION
This PowerShell script writes text centered and animated to the console.
.PARAMETER text
Specifies the text line to write ("Welcome to PowerShell" by default)
.PARAMETER speed
Specifies the animation speed per character (10ms by default)
.EXAMPLE
PS> ./write-animated.ps1
(watch and enjoy)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$text = "Welcome to PowerShell", [int]$speed = 10) # 10ms
function WriteLine([string]$line) {
[int]$end = $line.Length
$startPos = $HOST.UI.RawUI.CursorPosition
$spaces = " "
[int]$termHalfWidth = 120 / 2
foreach($pos in 1 .. $end) {
$HOST.UI.RawUI.CursorPosition = $startPos
Write-Host "$($spaces.Substring(0, $termHalfWidth - $pos / 2) + $line.Substring(0, $pos))" -noNewline
Start-Sleep -milliseconds $speed
}
Write-Host ""
}
try {
WriteLine $text
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}