PowerShell/docs/write-typewriter.md

86 lines
2.1 KiB
Markdown
Raw Normal View History

2024-11-08 12:38:20 +01:00
The *write-typewriter.ps1* Script
===========================
2021-11-08 21:36:42 +01:00
2022-11-17 19:46:02 +01:00
This PowerShell script writes the given text with the typewriter effect.
2021-11-08 21:36:42 +01:00
2023-07-29 10:04:38 +02:00
Parameters
----------
2021-11-08 21:36:42 +01:00
```powershell
2025-01-17 08:31:53 +01:00
/Repos/PowerShell/scripts/write-typewriter.ps1 [[-text] <String>] [[-speed] <Int32>] [<CommonParameters>]
2021-11-08 21:36:42 +01:00
-text <String>
2025-01-17 08:31:53 +01:00
Specifies the text to write (sample text by default)
2021-11-08 21:36:42 +01:00
Required? false
Position? 1
2025-01-17 08:31:53 +01:00
Default value Hello World, this is the PowerShell typewriter.
2021-11-08 21:36:42 +01:00
Accept pipeline input? false
Accept wildcard characters? false
-speed <Int32>
2025-01-17 08:31:53 +01:00
Specifies the speed (200 ms by default)
2021-11-08 21:36:42 +01:00
Required? false
Position? 2
2022-11-17 19:46:02 +01:00
Default value 200
2021-11-08 21:36:42 +01:00
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.
```
2023-07-29 10:04:38 +02:00
Example
-------
2021-11-08 21:36:42 +01:00
```powershell
2025-01-17 08:31:53 +01:00
PS> ./write-typewriter.ps1 "Hello World"
2021-11-08 21:36:42 +01:00
```
2023-07-29 10:04:38 +02:00
Notes
-----
2022-11-17 19:46:02 +01:00
Author: Markus Fleschutz | License: CC0
2021-11-08 21:36:42 +01:00
2023-07-29 10:04:38 +02:00
Related Links
-------------
2021-11-08 21:36:42 +01:00
https://github.com/fleschutz/PowerShell
2023-07-29 10:04:38 +02:00
Script Content
--------------
2022-11-17 20:05:34 +01:00
```powershell
2022-11-17 20:02:26 +01:00
<#
.SYNOPSIS
2025-01-17 08:31:53 +01:00
Writes text like a typewriter
2022-11-17 20:02:26 +01:00
.DESCRIPTION
This PowerShell script writes the given text with the typewriter effect.
.PARAMETER text
2025-01-17 08:31:53 +01:00
Specifies the text to write (sample text by default)
2022-11-17 20:02:26 +01:00
.PARAMETER speed
2025-01-17 08:31:53 +01:00
Specifies the speed (200 ms by default)
2022-11-17 20:02:26 +01:00
.EXAMPLE
2025-01-17 08:31:53 +01:00
PS> ./write-typewriter.ps1 "Hello World"
2022-11-17 20:02:26 +01:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2025-01-17 08:31:53 +01:00
param([string]$text = "Hello World, this is the PowerShell typewriter.", [int]$speed = 200) # in milliseconds
2022-11-17 20:02:26 +01:00
try {
$Random = New-Object System.Random
$text -split '' | ForEach-Object {
2025-01-17 08:31:53 +01:00
Write-Host $_ -noNewline
Start-Sleep -milliseconds $Random.Next($speed)
2022-11-17 20:02:26 +01:00
}
Write-Host ""
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
2022-11-17 20:05:34 +01:00
```
2022-11-17 20:02:26 +01:00
2025-01-23 12:15:35 +01:00
*(page generated by convert-ps2md.ps1 as of 01/23/2025 12:15:26)*