PoshCode Archive  Artifact [b13a7865da]

Artifact b13a7865dab4fa7f6bd47bec2f356bfff02aa5d48bb9b99e76ba25fdcae11620:

  • File Out-AnsiGraph.ps1 — part of check-in [51b3a213fa] at 2018-06-10 12:56:53 on branch trunk — Pipe numeric output into a horizontal ansi barchart in Psh. Poshcode doesn’t handle ANSI characters. Replace █ with an ANSI block character. Copy/Paste from http://xcud.com/post/193522355/out-ansigraph (user: xcud size: 1092)

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

	}
}

Export-ModuleMember Out-AnsiGraph