-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAnsiGraph.ps1
41 lines (37 loc) · 1.94 KB
/
AnsiGraph.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
41
#
# Out-AnsiGraph.psm1
# Author: xcud
# History:
# v0.1 September 21, 2009 initial version
#
# PS Example> ps | select -first 5 | sort -property VM | Out-AnsiGraph ProcessName, VM
# AEADISRV ███ 14508032
# audiodg █████████ 50757632
# conhost █████████████ 73740288
# AppleMobileDeviceService ████████████████ 92061696
# btdna █████████████████████ 126443520
#
function Out-AnsiGraph($Parameter1=$null) {
BEGIN {
$q = new-object Collections.queue
$max = 0; $namewidth = 0;
}
PROCESS {
if($_) {
$name = $_.($Parameter1[0]);
$val = $_.($Parameter1[1])
if($max -lt $val) { $max = $val}
if($namewidth -lt $name.length) {
$namewidth = $name.length }
$q.enqueue(@($name, $val))
}
}
END {
$q | %{
$graph = ""; 0..($_[1]/$max*20) |
%{ $graph += "█" }
$name = "{0,$namewidth}" -f $_[0]
"$name $graph " + $_[1]
}
}
}