PowerShell/Docs/write-animated.md

165 lines
4.3 KiB
Markdown
Raw Normal View History

2023-07-29 09:55:25 +02:00
## Script: *write-animated.ps1*
2021-11-08 21:36:42 +01:00
2023-07-29 09:45:37 +02:00
This PowerShell script writes animated text to the console.
2021-11-08 21:36:42 +01:00
## Parameters
```powershell
2023-07-29 09:45:37 +02:00
write-animated.ps1 [[-Line1] <Object>] [[-Line2] <Object>] [[-Line3] <Object>] [[-Line4] <Object>] [[-Line5] <Object>] [[-Line6] <Object>] [[-Line7] <Object>] [[-Line8] <Object>] [[-Line9] <Object>] [[-Speed] <Int32>] [<CommonParameters>]
2021-11-08 21:36:42 +01:00
-Line1 <Object>
Required? false
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Line2 <Object>
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Line3 <Object>
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Line4 <Object>
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Line5 <Object>
Required? false
Position? 5
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Line6 <Object>
Required? false
Position? 6
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Line7 <Object>
Required? false
Position? 7
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Line8 <Object>
Required? false
Position? 8
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Line9 <Object>
Required? false
Position? 9
Default value
Accept pipeline input? false
Accept wildcard characters? false
-Speed <Int32>
Required? false
Position? 10
Default value 30
Accept pipeline input? false
Accept wildcard characters? false
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
## Example
```powershell
PS> ./write-animated "Hello World"
```
## Notes
2022-11-17 19:46:02 +01:00
Author: Markus Fleschutz | License: CC0
2021-11-08 21:36:42 +01:00
## Related Links
https://github.com/fleschutz/PowerShell
2023-07-29 09:55:25 +02:00
## Script Content
2022-11-17 20:05:34 +01:00
```powershell
2022-11-17 20:02:26 +01:00
<#
.SYNOPSIS
Writes animated text
.DESCRIPTION
2023-07-29 09:45:37 +02:00
This PowerShell script writes animated text to the console.
2022-11-17 20:02:26 +01:00
.EXAMPLE
PS> ./write-animated "Hello World"
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param($Line1 = "", $Line2 = "", $Line3 = "", $Line4 = "", $Line5 = "", $Line6 = "", $Line7 = "", $Line8 = "", $Line9 = "", [int]$Speed = 30) # 30 ms pause
$TerminalWidth = 120 # characters
2023-07-29 09:45:37 +02:00
function WriteLine { param([string]$Line)
if ($Line -eq "") { return }
2022-11-17 20:02:26 +01:00
[int]$End = $Line.Length
$StartPosition = $HOST.UI.RawUI.CursorPosition
$Spaces = " "
2023-07-29 09:45:37 +02:00
foreach($Pos in 1 .. $End) {
2022-11-17 20:02:26 +01:00
$TextToDisplay = $Spaces.Substring(0, $TerminalWidth / 2 - $pos / 2) + $Line.Substring(0, $Pos)
2023-07-29 09:45:37 +02:00
Write-Host $TextToDisplay -noNewline
Start-Sleep -milliseconds $Speed
2022-11-17 20:02:26 +01:00
$HOST.UI.RawUI.CursorPosition = $StartPosition
}
2023-07-29 09:45:37 +02:00
Write-Host ""
2022-11-17 20:02:26 +01:00
}
2023-07-29 09:45:37 +02:00
try {
if ($Line1 -eq "") {
$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
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
2022-11-17 20:02:26 +01:00
}
2022-11-17 20:05:34 +01:00
```
2022-11-17 20:02:26 +01:00
2023-07-29 09:55:25 +02:00
*(generated by convert-ps2md.ps1 using the comment-based help of write-animated.ps1 as of 07/29/2023 09:55:16)*