mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-06-09 22:46:52 +02:00
Update write-animated.ps1
This commit is contained in:
parent
4ae2c279c7
commit
b45b9c0c3c
@ -2,7 +2,7 @@
|
|||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Writes animated text
|
Writes animated text
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script writes animated text.
|
This PowerShell script writes animated text to the console.
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./write-animated "Hello World"
|
PS> ./write-animated "Hello World"
|
||||||
.LINK
|
.LINK
|
||||||
@ -16,13 +16,11 @@ param($Line1 = "", $Line2 = "", $Line3 = "", $Line4 = "", $Line5 = "", $Line6 =
|
|||||||
$TerminalWidth = 120 # characters
|
$TerminalWidth = 120 # characters
|
||||||
|
|
||||||
function WriteLine { param([string]$Line)
|
function WriteLine { param([string]$Line)
|
||||||
[int]$Start = 1
|
if ($Line -eq "") { return }
|
||||||
[int]$End = $Line.Length
|
[int]$End = $Line.Length
|
||||||
$StartPosition = $HOST.UI.RawUI.CursorPosition
|
$StartPosition = $HOST.UI.RawUI.CursorPosition
|
||||||
$Spaces = " "
|
$Spaces = " "
|
||||||
|
foreach($Pos in 1 .. $End) {
|
||||||
if ($Line -eq "") { return }
|
|
||||||
foreach ($Pos in $Start .. $End) {
|
|
||||||
$TextToDisplay = $Spaces.Substring(0, $TerminalWidth / 2 - $pos / 2) + $Line.Substring(0, $Pos)
|
$TextToDisplay = $Spaces.Substring(0, $TerminalWidth / 2 - $pos / 2) + $Line.Substring(0, $Pos)
|
||||||
Write-Host $TextToDisplay -noNewline
|
Write-Host $TextToDisplay -noNewline
|
||||||
Start-Sleep -milliseconds $Speed
|
Start-Sleep -milliseconds $Speed
|
||||||
@ -31,22 +29,26 @@ function WriteLine { param([string]$Line)
|
|||||||
Write-Host ""
|
Write-Host ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Line1 -eq "") {
|
try {
|
||||||
|
if ($Line1 -eq "") {
|
||||||
$Line1 = "Welcome to PowerShell Scripts"
|
$Line1 = "Welcome to PowerShell Scripts"
|
||||||
$Line2 = " "
|
$Line2 = " "
|
||||||
$Line3 = "This repository contains useful and cross-platform PowerShell scripts."
|
$Line3 = "This repository contains useful and cross-platform PowerShell scripts."
|
||||||
$Line4 = " "
|
$Line4 = " "
|
||||||
$Line5 = "Best regards,"
|
$Line5 = "Best regards,"
|
||||||
$Line6 = "Markus"
|
$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
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteLine $Line1
|
|
||||||
WriteLine $Line2
|
|
||||||
WriteLine $Line3
|
|
||||||
WriteLine $Line4
|
|
||||||
WriteLine $Line5
|
|
||||||
WriteLine $Line6
|
|
||||||
WriteLine $Line7
|
|
||||||
WriteLine $Line8
|
|
||||||
WriteLine $Line9
|
|
||||||
exit 0 # success
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user