PowerShell/Scripts/write-animated.ps1

53 lines
1.3 KiB
PowerShell
Raw Normal View History

2021-09-27 10:38:12 +02: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
2022-01-30 10:49:30 +01:00
This PowerShell script writes animated text.
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)
2021-02-06 14:38:58 +01:00
[int]$Start = 1
[int]$End = $Line.Length
$StartPosition = $HOST.UI.RawUI.CursorPosition
$Spaces = " "
2021-05-04 20:43:38 +02:00
if ($Line -eq "") { return }
foreach ($Pos in $Start .. $End) {
$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
}
if ($Line1 -eq "") {
$Line1 = "Welcome to PowerShell Scripts"
2021-05-04 20:43:38 +02:00
$Line2 = " "
2021-02-06 14:38:58 +01:00
$Line3 = "This repository contains useful and cross-platform PowerShell scripts."
2021-05-04 20:43:38 +02:00
$Line4 = " "
2021-02-06 14:38:58 +01:00
$Line5 = "Best regards,"
$Line6 = "Markus"
}
2022-11-30 08:42:00 +01:00
2023-06-15 17:20:52 +02:00
WriteLine $Line1
WriteLine $Line2
WriteLine $Line3
WriteLine $Line4
WriteLine $Line5
WriteLine $Line6
WriteLine $Line7
WriteLine $Line8
WriteLine $Line9
2021-09-27 10:09:45 +02:00
exit 0 # success