mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-22 16:03:22 +01:00
Update write-morse-code.ps1
This commit is contained in:
parent
3876614b62
commit
b2424da287
@ -1,14 +1,15 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Writes text in Morse code
|
||||
Writes Morse code
|
||||
.DESCRIPTION
|
||||
This PowerShell script writes text in Morse code.
|
||||
This PowerShell script writes the given text in Morse code.
|
||||
.PARAMETER text
|
||||
Specifies the text to write
|
||||
.PARAMETER speed
|
||||
Specifies the speed of one time unit (100 ms per default)
|
||||
.EXAMPLE
|
||||
PS> ./write-morse-code "Hello World"
|
||||
PS> ./write-morse-code ABC
|
||||
● ― ― ● ● ● ― ● ― ●
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -18,20 +19,20 @@
|
||||
param([string]$text = "", [int]$speed = 100) # one time unit in milliseconds
|
||||
|
||||
function gap { param([int]$Length)
|
||||
for ([int]$i = 1; $i -lt $Length; $i++) {
|
||||
write-host " " -nonewline
|
||||
for ([int]$i = 0; $i -lt $Length; $i++) {
|
||||
Write-Host " " -noNewline
|
||||
}
|
||||
start-sleep -milliseconds ($Length * $speed)
|
||||
Start-Sleep -milliseconds ($Length * $speed)
|
||||
}
|
||||
|
||||
function dot {
|
||||
write-host "." -nonewline
|
||||
start-sleep -milliseconds $speed # signal
|
||||
Write-Host "●" -noNewline
|
||||
Start-Sleep -milliseconds $speed # signal
|
||||
}
|
||||
|
||||
function dash {
|
||||
write-host "_" -nonewline
|
||||
start-sleep -milliseconds (3 * $speed) # signal
|
||||
Write-Host "―" -noNewline
|
||||
Start-Sleep -milliseconds (3 * $speed) # signal
|
||||
}
|
||||
|
||||
function Char2MorseCode { param([string]$Char)
|
||||
@ -77,16 +78,14 @@ function Char2MorseCode { param([string]$Char)
|
||||
}
|
||||
|
||||
try {
|
||||
if ($text -eq "" ) { [string]$text = read-host "Enter text to write" }
|
||||
if ($text -eq "" ) { [string]$text = Read-Host "Enter text to write" }
|
||||
|
||||
[char[]]$ArrayOfChars = $text.ToUpper()
|
||||
foreach($Char in $ArrayOfChars) {
|
||||
Char2MorseCode $Char
|
||||
}
|
||||
write-host ""
|
||||
write-host ""
|
||||
exit 0 # success
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user