2023-10-31 11:25:11 +01:00
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
.SYNOPSIS
|
2021-09-25 19:43:22 +02:00
|
|
|
Writes animated text
|
2021-10-04 21:29:23 +02:00
|
|
|
.DESCRIPTION
|
2023-07-03 21:21:10 +02:00
|
|
|
This PowerShell script writes animated text to the console.
|
2021-07-13 21:10:02 +02:00
|
|
|
.EXAMPLE
|
2021-09-25 19:43:22 +02:00
|
|
|
PS> ./write-animated "Hello World"
|
2021-07-13 21:10:02 +02:00
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
2022-01-30 10:49:30 +01:00
|
|
|
.NOTES
|
2022-09-06 21:42:04 +02:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-02-06 14:38:58 +01:00
|
|
|
#>
|
|
|
|
|
2021-05-04 20:43:38 +02:00
|
|
|
param($Line1 = "", $Line2 = "", $Line3 = "", $Line4 = "", $Line5 = "", $Line6 = "", $Line7 = "", $Line8 = "", $Line9 = "", [int]$Speed = 30) # 30 ms pause
|
2021-02-06 14:38:58 +01:00
|
|
|
|
2021-04-22 08:56:07 +02:00
|
|
|
$TerminalWidth = 120 # characters
|
|
|
|
|
2023-06-15 17:20:52 +02:00
|
|
|
function WriteLine { param([string]$Line)
|
2023-07-03 21:21:10 +02:00
|
|
|
if ($Line -eq "") { return }
|
2021-02-06 14:38:58 +01:00
|
|
|
[int]$End = $Line.Length
|
|
|
|
$StartPosition = $HOST.UI.RawUI.CursorPosition
|
|
|
|
$Spaces = " "
|
2023-07-03 21:21:10 +02:00
|
|
|
foreach($Pos in 1 .. $End) {
|
2021-05-04 20:43:38 +02:00
|
|
|
$TextToDisplay = $Spaces.Substring(0, $TerminalWidth / 2 - $pos / 2) + $Line.Substring(0, $Pos)
|
2023-06-15 17:20:52 +02:00
|
|
|
Write-Host $TextToDisplay -noNewline
|
|
|
|
Start-Sleep -milliseconds $Speed
|
2021-05-04 20:43:38 +02:00
|
|
|
$HOST.UI.RawUI.CursorPosition = $StartPosition
|
2021-02-06 14:38:58 +01:00
|
|
|
}
|
2023-06-15 17:20:52 +02:00
|
|
|
Write-Host ""
|
2021-02-06 14:38:58 +01:00
|
|
|
}
|
|
|
|
|
2023-07-03 21:21:10 +02:00
|
|
|
try {
|
|
|
|
if ($Line1 -eq "") {
|
|
|
|
$Line1 = "Welcome to PowerShell Scripts"
|
|
|
|
$Line2 = " "
|
|
|
|
$Line3 = "This repository contains useful and cross-platform PowerShell scripts."
|
|
|
|
$Line4 = " "
|
|
|
|
$Line5 = "Best regards,"
|
|
|
|
$Line6 = "Markus"
|
|
|
|
}
|
|
|
|
WriteLine $Line1
|
|
|
|
WriteLine $Line2
|
|
|
|
WriteLine $Line3
|
|
|
|
WriteLine $Line4
|
|
|
|
WriteLine $Line5
|
|
|
|
WriteLine $Line6
|
|
|
|
WriteLine $Line7
|
|
|
|
WriteLine $Line8
|
|
|
|
WriteLine $Line9
|
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
2021-02-06 14:38:58 +01:00
|
|
|
}
|