mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-08-09 21:07:40 +02:00
Renamed folder Scripts to scripts
This commit is contained in:
49
scripts/write-chart.ps1
Executable file
49
scripts/write-chart.ps1
Executable file
@ -0,0 +1,49 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Writes a chart
|
||||
.DESCRIPTION
|
||||
This PowerShell script writes an horizontal chart to the console.
|
||||
.EXAMPLE
|
||||
PS> ./write-chart.ps1
|
||||
|
||||
2023 BOWLING RESULTS
|
||||
████████████████▏ 40.5% Joe
|
||||
████████████▎ 30.9% Tom
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
Author: Markus Fleschutz | License: CC0
|
||||
#>
|
||||
|
||||
function WriteChartLine { param([string]$Text, [float]$Value, [float]$Max)
|
||||
$Num = ($Value * 40.0) / $Max
|
||||
while ($Num -ge 1.0) {
|
||||
Write-Host -noNewLine "█"
|
||||
$Num -= 1.0
|
||||
}
|
||||
if ($Num -ge 0.875) {
|
||||
Write-Host -noNewLine "▉"
|
||||
} elseif ($Num -ge 0.75) {
|
||||
Write-Host -noNewLine "▊"
|
||||
} elseif ($Num -ge 0.625) {
|
||||
Write-Host -noNewLine "▋"
|
||||
} elseif ($Num -ge 0.5) {
|
||||
Write-Host -noNewLine "▌"
|
||||
} elseif ($Num -ge 0.375) {
|
||||
Write-Host -noNewLine "▍"
|
||||
} elseif ($Num -ge 0.25) {
|
||||
Write-Host -noNewLine "▎"
|
||||
} elseif ($Num -ge 0.125) {
|
||||
Write-Host -noNewLine "▏"
|
||||
}
|
||||
if ($Max -eq 100.0) {
|
||||
Write-Host " $($Value)% $Text"
|
||||
} else {
|
||||
Write-Host " $Value / $Max $Text"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "`n2023 BOWLING RESULTS" -foregroundColor green
|
||||
WriteChartLine "Joe" 40.5 100.0
|
||||
WriteChartLine "Tom" 30.9 100.0
|
||||
exit 0 # success
|
Reference in New Issue
Block a user