diff --git a/Scripts/write-morse-code.ps1 b/Scripts/write-morse-code.ps1 index 7a78c6df..17f6e918 100755 --- a/Scripts/write-morse-code.ps1 +++ b/Scripts/write-morse-code.ps1 @@ -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 -} +} \ No newline at end of file