-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathNew-RedGreenGradient.ps1
41 lines (34 loc) · 1.26 KB
/
New-RedGreenGradient.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Function New-RedGreenGradient {
[cmdletbinding()]
[OutputType([System.String])]
Param(
[Parameter(Position = 0, HelpMessage = "Specify a percentage as a decimal value like .35")]
[ValidateScript( {$_ -le 1})]
[double]$Percent = 1,
[Parameter(HelpMessage = "Specify a relative bar length. The smaller the number the longer the bar.")]
[ValidateRange(2, 10)]
[int]$Step = 5,
[Parameter(HelpMessage = "Specify a character to use for the gradient bar")]
[char]$Character = 0x2588
)
Write-Verbose "Starting $($MyInvocation.MyCommand)"
$r = 255
$g = 0
Write-Verbose "Using a percentage of $Percent"
[int]$max = $r*$Percent
Write-Verbose "Using a calculated max value of $max"
[string[]]$out = @()
Write-Verbose "Looping from through with a step value of $step"
for ($i = 0; $i -le $max; $i += $Step) {
$out += "$([char]0x1b)[38;2;$r;$g;0m$Character$([char]0x1b)[0m"
$r -= $Step
$g += $Step
if ($g -ge 256) {
Write-Verbose "100% green has been reached"
break
}
}
Write-Verbose "Creating final ANSI gradient bar"
$out -join ""
Write-Verbose "Ending $($MyInvocation.MyCommand)"
} #end function