Updated write-value.ps1

This commit is contained in:
Markus Fleschutz 2024-12-02 20:13:11 +01:00
parent 1ed0d1c6a0
commit 647206ee13

View File

@ -2,7 +2,7 @@
.SYNOPSIS .SYNOPSIS
Writes a value with value range Writes a value with value range
.DESCRIPTION .DESCRIPTION
This PowerShell script writes the given value to stdout. This PowerShell script writes the given value with value range to the console.
.PARAMETER value .PARAMETER value
Specifies the value Specifies the value
.EXAMPLE .EXAMPLE
@ -16,49 +16,50 @@
param([float]$value = 0.5, [string]$unit = "Mach", [float]$min = 0.0, [float]$max = 10.0) param([float]$value = 0.5, [string]$unit = "Mach", [float]$min = 0.0, [float]$max = 10.0)
function WriteLine([float]$count) function WriteLine([float]$count) {
{ while ($count -ge 1.0) {
for ([int]$i = 0; $i -lt $count; $i++) {
Write-Host "" -noNewline Write-Host "" -noNewline
$count -= 1.0
} }
return $count
} }
function WriteBlock([float]$value, [string]$unit, [float]$min, [float]$max) { function WriteBlock([float]$value, [string]$unit, [float]$min, [float]$max) {
$text = "[$min $value $unit $max]" $text = "[$min $($value)$unit $max]"
$left = 32 - $text.Length [float]$left = 20.0 - $text.Length
if ($value -gt $max) { if ($value -gt $max) {
Write-Host "[$min" -noNewline Write-Host "[$min" -noNewline
WriteLine $left $rest = WriteLine $left
Write-Host "$max]" -noNewline Write-Host "$max]" -noNewline
Write-Host " $value $unit " -noNewline -foregroundColor red Write-Host " $($value)$unit " -noNewline -foregroundColor red
} elseif ($value -lt $min) { } elseif ($value -lt $min) {
Write-Host "$value $unit" -noNewline -foregroundColor red Write-Host "$($value)$unit" -noNewline -foregroundColor red
Write-Host " [$min" -noNewline Write-Host " [$min" -noNewline
WriteLine $left $rest = WriteLine $left
Write-Host "$max] " -noNewline Write-Host "$max] " -noNewline
} else { } else {
[float]$percent = ($value * 100.0) / $max [float]$percent = (($value - $min) * $left) / ($max - $min)
Write-Host "[$min" -noNewline Write-Host "[$min" -noNewline
WriteLine ($percent / 5.0) $rest = WriteLine $percent
Write-Host "$value $unit" -noNewline -foregroundColor green Write-Host "$($value)$unit" -noNewline -foregroundColor green
WriteLine ((100.0 - $percent) / 5.0) $rest = WriteLine ($left - $percent + $rest + 1.0)
Write-Host "$max] " -noNewline Write-Host "$max] " -noNewline
} }
} }
WriteBlock -11.5 "Mach" 0.0 10.0 WriteBlock -3.5 "°C" 0 100
Write-Host "Too slow" Write-Host "CPU too cold"
WriteBlock 0.5 "Mach" 0.0 10.0 WriteBlock 15 "°C" 0 100
Write-Host "Good" Write-Host "OK"
WriteBlock 5 "Mach" 0.0 10.0 WriteBlock 50 "°C" 0 100
Write-Host "Good" Write-Host "OK"
WriteBlock 7 "Mach" 0.0 10.0 WriteBlock 70 "°C" 0 100
Write-Host "Good" Write-Host "OK"
WriteBlock 15 "Mach" 0.0 10.0 WriteBlock 110 "°C" 0 100
Write-Host "Too fast" Write-Host "CPU too hot "
exit 0 # success exit 0 # success