forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNew-ANSIBar.ps1
More file actions
71 lines (64 loc) · 2.44 KB
/
New-ANSIBar.ps1
File metadata and controls
71 lines (64 loc) · 2.44 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Function New-ANSIBar {
[cmdletbinding(DefaultParameterSetName = "standard")]
Param(
[Parameter(Mandatory, HelpMessage = "Enter a range of 256 color values, e.g. (232..255)")]
[ValidateNotNullOrEmpty()]
[int[]]$Range,
[Parameter(HelpMessage = "How many characters do you want in the bar of each value? This will increase the overall length of the bar.")]
[int]$Spacing = 1,
[Parameter(ParameterSetName = "standard", HelpMessage = "Specify a character to use for the bar.")]
[ValidateSet("FullBlock", "LightShade", "MediumShade", "DarkShade", "BlackSquare", "WhiteSquare")]
[string]$Character = "FullBlock",
[Parameter(ParameterSetName = "custom", HelpMessage = "Specify a custom character.")]
[char]$Custom,
[Parameter(HelpMessage = "Display as a single gradient from the first value to the last.")]
[switch]$Gradient
)
Write-Verbose "Starting $($myinvocation.mycommand)"
Write-Verbose "Using parameter set $($pscmdlet.ParameterSetName)"
if ($pscmdlet.ParameterSetName -eq "Standard") {
Write-Verbose "Using standard character $character"
Switch ($Character) {
"FullBlock" {
$ch = $([char]0x2588)
}
"LightShade" {
$ch = $([char]0x2591)
}
"MediumShade" {
$ch = $([char]0x2592)
}
"DarkShade" {
$ch = $([char]0x2593)
}
"BlackSquare" {
$ch = $([char]0x25A0)
}
"WhiteSquare" {
$ch = [char]0x25A1
}
}
}
else {
Write-Verbose "Using custom character $custom (which may not display here)"
$ch = $Custom
}
$esc = "$([char]0x1b)"
$out = @()
$blank = "$($ch)"*$spacing
if ($Gradient) {
Write-Verbose "Creating gradient ANSI bar from $($range[0]) to $($range[-1])"
$out += $range | ForEach-Object { "$esc[38;5;$($_)m$($blank)$esc[0m" }
}
else {
Write-Verbose "Creating standard ANSI bar from $($range[0]) to $($range[-1])"
$out += $range | ForEach-Object {
"$esc[38;5;$($_)m$($blank)$esc[0m"
}
$out += $range | Sort-Object -Descending | ForEach-Object {
"$esc[38;5;$($_)m$($blank)$esc[0m"
}
}
$out -join ""
Write-Verbose "Starting $($myinvocation.mycommand)"
} #close function