mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-22 18:08:18 +02:00
Update write-animated.ps1
This commit is contained in:
parent
deca430aae
commit
bc9a0ab7c0
@ -2,51 +2,37 @@
|
|||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Writes animated text
|
Writes animated text
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script writes animated text to the console.
|
This PowerShell script writes text centered and animated to the console.
|
||||||
|
.PARAMETER text
|
||||||
|
Specifies the text line to write ("Welcome to PowerShell" by default)
|
||||||
|
.PARAMETER speed
|
||||||
|
Specifies the animation speed per character (10ms by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./write-animated "Hello World"
|
PS> ./write-animated.ps1
|
||||||
|
(watch and enjoy)
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
Author: Markus Fleschutz | License: CC0
|
Author: Markus Fleschutz | License: CC0
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param($Line1 = "", $Line2 = "", $Line3 = "", $Line4 = "", $Line5 = "", $Line6 = "", $Line7 = "", $Line8 = "", $Line9 = "", [int]$Speed = 30) # 30 ms pause
|
param([string]$text = "Welcome to PowerShell", [int]$speed = 10) # 10ms
|
||||||
|
|
||||||
$TerminalWidth = 120 # characters
|
function WriteLine([string]$line) {
|
||||||
|
[int]$end = $line.Length
|
||||||
function WriteLine { param([string]$Line)
|
$startPos = $HOST.UI.RawUI.CursorPosition
|
||||||
if ($Line -eq "") { return }
|
$spaces = " "
|
||||||
[int]$End = $Line.Length
|
[int]$termHalfWidth = 120 / 2
|
||||||
$StartPosition = $HOST.UI.RawUI.CursorPosition
|
foreach($pos in 1 .. $end) {
|
||||||
$Spaces = " "
|
$HOST.UI.RawUI.CursorPosition = $startPos
|
||||||
foreach($Pos in 1 .. $End) {
|
Write-Host "$($spaces.Substring(0, $termHalfWidth - $pos / 2) + $line.Substring(0, $pos))" -noNewline
|
||||||
$TextToDisplay = $Spaces.Substring(0, $TerminalWidth / 2 - $pos / 2) + $Line.Substring(0, $Pos)
|
Start-Sleep -milliseconds $speed
|
||||||
Write-Host $TextToDisplay -noNewline
|
|
||||||
Start-Sleep -milliseconds $Speed
|
|
||||||
$HOST.UI.RawUI.CursorPosition = $StartPosition
|
|
||||||
}
|
}
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($Line1 -eq "") {
|
WriteLine $text
|
||||||
$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
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user