mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-05-09 10:04:45 +02:00
Added write-centered.ps1
This commit is contained in:
parent
6132292e2a
commit
d9f5847aed
33
scripts/write-centered.ps1
Normal file
33
scripts/write-centered.ps1
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Writes text centered
|
||||||
|
.DESCRIPTION
|
||||||
|
This PowerShell script writes the given text centered to the console.
|
||||||
|
.PARAMETER text
|
||||||
|
Specifies the text to write
|
||||||
|
.EXAMPLE
|
||||||
|
PS> ./write-headline.ps1 "Hello World"
|
||||||
|
Hello World
|
||||||
|
.LINK
|
||||||
|
https://github.com/fleschutz/PowerShell
|
||||||
|
.NOTES
|
||||||
|
Author: Markus Fleschutz | License: CC0
|
||||||
|
#>
|
||||||
|
|
||||||
|
param([string]$text = "")
|
||||||
|
|
||||||
|
try {
|
||||||
|
if ($text -eq "") { $text = Read-Host "Enter the text to write" }
|
||||||
|
|
||||||
|
$ui = (Get-Host).ui
|
||||||
|
$rui = $ui.rawui
|
||||||
|
[int]$numSpaces = ($rui.MaxWindowSize.Width - $text.Length) / 2
|
||||||
|
|
||||||
|
[string]$spaces = ""
|
||||||
|
for ([int]$i = 0; $i -lt $numSpaces; $i++) { $spaces += " " }
|
||||||
|
Write-Host "$spaces$text"
|
||||||
|
exit 0 # success
|
||||||
|
} catch {
|
||||||
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
exit 1
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
Writes text as headline
|
Writes a headline
|
||||||
.DESCRIPTION
|
.DESCRIPTION
|
||||||
This PowerShell script writes the given text as a headline.
|
This PowerShell script writes the given text as a headline.
|
||||||
.PARAMETER text
|
.PARAMETER text
|
||||||
Specifies the headline text
|
Specifies the text to write
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./write-headline.ps1 "Hello World"
|
PS> ./write-headline.ps1 "Hello World"
|
||||||
|
|
||||||
@ -17,8 +17,9 @@
|
|||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$text = "")
|
param([string]$text = "")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($text -eq "") { $text = Read-Host "Enter the headline text" }
|
if ($text -eq "") { $text = Read-Host "Enter the text to write" }
|
||||||
|
|
||||||
Write-Host "`n* $text *" -foregroundColor green
|
Write-Host "`n* $text *" -foregroundColor green
|
||||||
[int]$len = $text.Length
|
[int]$len = $text.Length
|
||||||
|
Loading…
Reference in New Issue
Block a user