# encoding: ascii
# api: powershell
# title: Out-AnsiGraph
# description: Pipe numeric output into a horizontal ansi barchart in Psh. Poshcode doesn’t handle ANSI characters. Replace &#9608; with an ANSI block character. Copy/Paste from http://xcud.com/post/193522355/out-ansigraph
# version: 0.1
# type: function
# author: xcud
# license: CC0
# function: Out-AnsiGraph
# x-poshcode-id: 1335
# x-archived: 2009-09-28T13:19:04
#
#
#
# Out-AnsiGraph.psm1
# Author:       xcud
# History:
#       v0.1 September 21, 2009 initial version
#
function Out-AnsiGraph($Parameter1=$null) {
	BEGIN {
		$q = new-object Collections.queue
	}

	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 += "&#9608;" }
			$name = "{0,$namewidth}" -f $_[0]
			"$name $graph " + $_[1]
		}

	}
}

Export-ModuleMember Out-AnsiGraph
