PowerShell/Scripts/write-animated.ps1

54 lines
1.4 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
2021-05-04 20:43:38 +02:00
function WriteLine { param([string]$Line, [int]$Speed)
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)
write-host -nonewline $TextToDisplay
start-sleep -milliseconds $Speed
$HOST.UI.RawUI.CursorPosition = $StartPosition
2021-02-06 14:38:58 +01:00
}
2021-05-04 20:43:38 +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"
}
write-host ""
2021-05-04 20:43:38 +02:00
WriteLine $Line1 $Speed
WriteLine $Line2 $Speed
WriteLine $Line3 $Speed
WriteLine $Line4 $Speed
WriteLine $Line5 $Speed
WriteLine $Line6 $Speed
WriteLine $Line7 $Speed
WriteLine $Line8 $Speed
WriteLine $Line9 $Speed
2021-02-06 14:44:58 +01:00
write-host ""
2021-09-27 10:09:45 +02:00
exit 0 # success