PowerShell/Scripts/write-animated.ps1

55 lines
1.4 KiB
PowerShell
Raw Normal View History

2021-08-26 10:46:12 +02:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
write-animated.ps1 [<line1>] .. [line9>] [<speed>]
.DESCRIPTION
Writes animated text
.EXAMPLE
PS> .\write-animated.ps1 "Hello World"
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
2021-08-03 15:53:57 +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-02-06 14:38:58 +01:00
exit 0